fix(build): resolve Android build failures with Java 21 and Capacitor context
Fixed two build issues preventing Android plugin compilation:
1. Build script now builds from test app context instead of standalone
- Capacitor Android is only available as a project dependency, not from Maven
- Plugin must be built within a Capacitor app's Android project
- Changed build_plugin_for_test_app() to build from test app's android/
directory where Capacitor is available as :capacitor-android project
2. Added JVM arguments for Java 17+ KAPT compatibility
- Java 21's module system blocks KAPT from accessing internal compiler classes
- Added --add-opens flags to both org.gradle.jvmargs and kotlin.daemon.jvmargs
- Kotlin compiler daemon runs separately and needs its own configuration
- Applied to both plugin and test app gradle.properties files
These changes allow the plugin to build successfully with Java 21 and ensure
it's built in the correct context where Capacitor dependencies are available.
This commit is contained in:
@@ -76,30 +76,8 @@ build_typescript() {
|
||||
build_plugin_for_test_app() {
|
||||
log_info "Building plugin for test app..."
|
||||
|
||||
# Build the plugin AAR
|
||||
log_info "Building plugin AAR..."
|
||||
cd android || exit 1
|
||||
if ! ./gradlew :plugin:clean :plugin:assembleDebug; then
|
||||
log_error "Plugin build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
AAR_FILE="plugin/build/outputs/aar/plugin-debug.aar"
|
||||
if [ ! -f "$AAR_FILE" ]; then
|
||||
log_error "AAR file not found at $AAR_FILE"
|
||||
exit 1
|
||||
fi
|
||||
log_info "Plugin AAR built: $AAR_FILE"
|
||||
|
||||
# Remove any stale AAR from test app's libs directory
|
||||
if [ -f "../test-apps/daily-notification-test/android/app/libs/plugin-debug.aar" ]; then
|
||||
log_info "Removing stale AAR from test app libs..."
|
||||
rm "../test-apps/daily-notification-test/android/app/libs/plugin-debug.aar"
|
||||
fi
|
||||
|
||||
cd ..
|
||||
|
||||
# Ensure symlink is in place
|
||||
# Ensure symlink is in place FIRST (before building)
|
||||
# The test app expects the plugin at node_modules/@timesafari/daily-notification-plugin
|
||||
SYMLINK="test-apps/daily-notification-test/node_modules/@timesafari/daily-notification-plugin"
|
||||
if [ ! -L "$SYMLINK" ] || [ ! -e "$SYMLINK" ]; then
|
||||
log_info "Creating symlink to plugin..."
|
||||
@@ -108,22 +86,32 @@ build_plugin_for_test_app() {
|
||||
ln -sf "../../../" "$SYMLINK"
|
||||
fi
|
||||
|
||||
# Build test app
|
||||
log_info "Building test app..."
|
||||
# Build the plugin and test app from within the test app's Android project context
|
||||
# This is necessary because Capacitor Android is only available as a project dependency
|
||||
# The plugin will be built automatically as a dependency of the app
|
||||
log_info "Building plugin and test app from test app context..."
|
||||
cd test-apps/daily-notification-test/android || exit 1
|
||||
|
||||
# Build test app (this will automatically build the plugin as a dependency)
|
||||
if ! ./gradlew clean assembleDebug; then
|
||||
log_error "Test app build failed"
|
||||
log_error "Build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify plugin was built (optional check)
|
||||
PLUGIN_AAR="$(find . -name "*.aar" -path "*/timesafari-daily-notification-plugin/*" 2>/dev/null | head -1)"
|
||||
if [ -n "$PLUGIN_AAR" ]; then
|
||||
log_info "Plugin AAR built: $PLUGIN_AAR"
|
||||
fi
|
||||
|
||||
# Verify APK was built
|
||||
APK_FILE="app/build/outputs/apk/debug/app-debug.apk"
|
||||
if [ ! -f "$APK_FILE" ]; then
|
||||
log_error "APK file not found at $APK_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Test app build successful: $APK_FILE"
|
||||
log_info "Build successful: $APK_FILE"
|
||||
log_info "Install with: adb install -r $APK_FILE"
|
||||
|
||||
cd ../../..
|
||||
|
||||
Reference in New Issue
Block a user