From 8c45e2e0ef50e9896e9c2da0a80cb378ebe20d93 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Thu, 15 Oct 2026 12:39:24 -0500 Subject: [PATCH 1/3] fix(android): resolve js engine aar directly instead of via postinstall script --- apps/example-app/android/app/build.gradle | 8 --- .../capacitor-plugin/android/build.gradle | 6 +- packages/capacitor-plugin/package.json | 6 +- .../capacitor-plugin/scripts/install_libs.js | 69 ------------------- 4 files changed, 3 insertions(+), 86 deletions(-) delete mode 100644 packages/capacitor-plugin/scripts/install_libs.js diff --git a/apps/example-app/android/app/build.gradle b/apps/example-app/android/app/build.gradle index c8127ac4..85514329 100644 --- a/apps/example-app/android/app/build.gradle +++ b/apps/example-app/android/app/build.gradle @@ -50,11 +50,3 @@ try { } catch(Exception e) { logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work") } - -// BEGIN @capacitor/background-runner -repositories { - flatDir { - dirs '../../../../packages/capacitor-plugin/android/src/main/libs' - } -} -// END @capacitor/background-runner diff --git a/packages/capacitor-plugin/android/build.gradle b/packages/capacitor-plugin/android/build.gradle index 56e576be..f0a6c0e4 100644 --- a/packages/capacitor-plugin/android/build.gradle +++ b/packages/capacitor-plugin/android/build.gradle @@ -48,16 +48,12 @@ android { repositories { google() mavenCentral() - flatDir { - dirs "./src/main/libs", "libs" - dirs "$rootDir/../node_modules/@capacitor/background-runner/android/src/main/libs", "libs" - } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':capacitor-android') - implementation ":android-js-engine-release@aar" + implementation files('src/main/libs/android-js-engine-release.aar') implementation "androidx.work:work-runtime-ktx:$workManagerVersion" implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" implementation "androidx.core:core:$androidxCoreVersion" diff --git a/packages/capacitor-plugin/package.json b/packages/capacitor-plugin/package.json index fbc2b99a..6a477816 100644 --- a/packages/capacitor-plugin/package.json +++ b/packages/capacitor-plugin/package.json @@ -14,7 +14,6 @@ "ios/Sources", "ios/Tests", "Package.swift", - "scripts/install_libs.js", "CapacitorBackgroundRunner.podspec" ], "author": "Ionic Team", @@ -33,7 +32,7 @@ "scripts": { "verify": "npm run verify:ios && npm run verify:android && npm run verify:web", "verify:ios": "xcodebuild -scheme CapacitorBackgroundRunner -destination generic/platform=iOS && xcodebuild test -scheme CapacitorBackgroundRunner -destination 'platform=iOS Simulator,OS=26.0.1,name=iPhone 17 Pro'", - "verify:android": "cd android && ./gradlew clean build test && cd ..", + "verify:android": "cd android && ./gradlew clean test lint compileReleaseKotlin && cd ..", "verify:web": "npm run build", "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint", "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format", @@ -47,8 +46,7 @@ "pack": "npm run build && ./scripts/copy-native-sdks.sh && pnpm pack && mv ./capacitor-background-runner-*.tgz ../../", "clean": "rimraf ./dist", "watch": "tsc --watch", - "prepublishOnly": "npm run build", - "postinstall": "node ./scripts/install_libs.js" + "prepublishOnly": "npm run build" }, "devDependencies": { "@capacitor/android": "next", diff --git a/packages/capacitor-plugin/scripts/install_libs.js b/packages/capacitor-plugin/scripts/install_libs.js deleted file mode 100644 index 0fb44c09..00000000 --- a/packages/capacitor-plugin/scripts/install_libs.js +++ /dev/null @@ -1,69 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const msgPrefix = '[@capacitor/background-runner]'; - -let workingDir = process.env.INIT_CWD; -if (!workingDir) { - workingDir = '.'; -} - -if (!fs.existsSync(path.join(workingDir, 'android'))) { - console.warn( - `${msgPrefix} cannot install android-js-engine library: @capacitor/android not installed, or in wrong parent directory.`, - ); - return; -} - -const androidGradlePath = path.join(workingDir, 'android/app/build.gradle'); - -if (!fs.existsSync(androidGradlePath)) { - console.warn(`${msgPrefix} android build.gradle file not found`); - return; -} - -const startMarker = '// BEGIN @capacitor/background-runner'; -const endMarker = '// END @capacitor/background-runner'; -const legacyDirsLine = /^.*dirs\s+'[^']*@capacitor\/background-runner\/android\/src\/main\/libs'.*\r?\n/gm; - -const libsPath = path.resolve(__dirname, '../android/src/main/libs'); - -if (!fs.existsSync(libsPath)) { - console.warn(`${msgPrefix} android libs directory not found at ${libsPath}`); - return; -} - -const libsDir = path - .relative(path.dirname(path.resolve(androidGradlePath)), libsPath) - .split(path.sep) - .join('/'); - -let gradleFile = fs.readFileSync(androidGradlePath).toString('utf-8'); - -const blockStart = gradleFile.indexOf(startMarker); -const blockEnd = gradleFile.indexOf(endMarker); -if (blockStart !== -1 && blockEnd > blockStart) { - gradleFile = gradleFile.substring(0, blockStart) + gradleFile.substring(blockEnd + endMarker.length); -} - -gradleFile = gradleFile.replace(legacyDirsLine, ''); - -const block = [ - startMarker, - 'repositories {', - ' flatDir {', - ` dirs '${libsDir}'`, - ' }', - '}', - endMarker, -].join('\n'); - -fs.writeFileSync(androidGradlePath, `${gradleFile.trimEnd()}\n\n${block}\n`); - -// remove old version of aar -const oldReleaseAARPath = path.join(workingDir, 'android/src/main/libs/android-js-engine-release.aar'); -if (fs.existsSync(oldReleaseAARPath)) { - fs.rmSync(oldReleaseAARPath); -} - -console.log(`${msgPrefix} installed lib path to gradle repositories`); From 8615d2e0aee503b17b96a254dcc781c76ca55d60 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Thu, 15 Oct 2026 16:03:43 -0500 Subject: [PATCH 2/3] docs: drop Android flatDir setup step from READMEs --- README.md | 18 ++++-------------- packages/capacitor-plugin/README.md | 18 ++++-------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 9367938b..5a963769 100644 --- a/README.md +++ b/README.md @@ -79,22 +79,12 @@ Apple requires privacy descriptions to be specified in `Info.plist` for location ## Android -Insert the following line to `android/app/build.gradle`: +No additional setup is required. -```diff -... +If you are upgrading an existing Android project, the following leftovers from earlier versions are no longer used and can be deleted: -repositories { - flatDir{ - dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs' -+ dirs '../../node_modules/@capacitor/background-runner/android/src/main/libs', 'libs' - } -} -... - -``` - -If you are upgrading from 1.0.5 with an existing Android project, be sure to delete the `android-js-engine-release.aar` from `android/src/main/libs`. +- in `android/app/build.gradle`, the `dirs '../../node_modules/@capacitor/background-runner/android/src/main/libs', 'libs'` line inside the `flatDir` block +- `android/src/main/libs/android-js-engine-release.aar`, if you upgraded from 1.0.5 or earlier ### Geolocation diff --git a/packages/capacitor-plugin/README.md b/packages/capacitor-plugin/README.md index 9367938b..5a963769 100644 --- a/packages/capacitor-plugin/README.md +++ b/packages/capacitor-plugin/README.md @@ -79,22 +79,12 @@ Apple requires privacy descriptions to be specified in `Info.plist` for location ## Android -Insert the following line to `android/app/build.gradle`: +No additional setup is required. -```diff -... +If you are upgrading an existing Android project, the following leftovers from earlier versions are no longer used and can be deleted: -repositories { - flatDir{ - dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs' -+ dirs '../../node_modules/@capacitor/background-runner/android/src/main/libs', 'libs' - } -} -... - -``` - -If you are upgrading from 1.0.5 with an existing Android project, be sure to delete the `android-js-engine-release.aar` from `android/src/main/libs`. +- in `android/app/build.gradle`, the `dirs '../../node_modules/@capacitor/background-runner/android/src/main/libs', 'libs'` line inside the `flatDir` block +- `android/src/main/libs/android-js-engine-release.aar`, if you upgraded from 1.0.5 or earlier ### Geolocation From ff85fe9c7516102a5c815549e7e6200f4900c139 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Fri, 16 Oct 2026 09:16:21 -0500 Subject: [PATCH 3/3] enforce lint errors and document AAR build limitation --- CONTRIBUTING.md | 2 ++ packages/capacitor-plugin/android/build.gradle | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3f875180..6fed5591 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,6 +35,8 @@ Build and validate the web and native projects. This is useful to run in CI to verify that the plugin builds for all platforms. +> **Note**: On Android, the plugin's Gradle module cannot be assembled into an AAR, because it depends on the JS engine through a local `.aar` file and the Android Gradle Plugin rejects direct local `.aar` dependencies when building an AAR. `verify:android` therefore runs `test`, `lint`, and `compileReleaseKotlin` instead of `build`. This is not a limitation in practice: the plugin is consumed as a Gradle source module (`project(':capacitor-background-runner')`), never as a published AAR. To validate Android packaging end to end, build a consuming app — for example `apps/example-app/android` — which exercises manifest merging, resource merging, and native library packaging. + #### `npm run lint` / `npm run fmt` Check formatting and code quality, autoformat/autofix if possible. diff --git a/packages/capacitor-plugin/android/build.gradle b/packages/capacitor-plugin/android/build.gradle index f0a6c0e4..dacf05ce 100644 --- a/packages/capacitor-plugin/android/build.gradle +++ b/packages/capacitor-plugin/android/build.gradle @@ -36,8 +36,8 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - lintOptions { - abortOnError = false + lint { + abortOnError = true } compileOptions { sourceCompatibility JavaVersion.VERSION_21