Cordova AndroidX Build Plugin
The `cordova-androidx-build` plugin (current stable version 1.0.4) automatically migrates Cordova project code between Android Support Libraries and AndroidX libraries during the build process. This plugin is crucial for maintaining compatibility across different `cordova-android` versions, especially those transitioning to or already using AndroidX (e.g., `cordova-android@9` and newer). A key differentiator is its use of Gradle scripts, enabling it to work reliably on both local development machines and cloud build services like PhoneGap Build, which is not possible with hook-script-based alternatives such as `cordova-plugin-androidx-adapter`. It provides bidirectional migration capabilities, ensuring plugins build correctly whether the target project uses older Support Libraries or the newer AndroidX ecosystem. Release cadence is typically on an as-needed basis to address compatibility issues or updates in the Android build ecosystem.
Common errors
-
Manifest merger failed : Attribute application@appComponentFactory value=(...) from [...] AndroidManifest.xml:22:18-91 is also present at [...] AndroidManifest.xml:24:18-91 value=(...). Suggest: don't use tools:replace on <application> element with android:appComponentFactory yet; see https://issuetracker.google.com/issues/116239167
cause Conflicting AndroidX and Support Library declarations in `AndroidManifest.xml`, often due to mixing components that expect different library versions.fixThis plugin is designed to mitigate such issues. If this error persists, ensure all other plugins are AndroidX compatible or that `cordova-androidx-build` is correctly installed and integrated. You may need to manually inspect your project's `AndroidManifest.xml` files for conflicting entries or check individual plugin dependencies. -
AAPT: error: resource android:attr/fontVariationSettings not found.
cause This error typically indicates that an older `compileSdkVersion` or `targetSdkVersion` is being used with a newer AndroidX library component that requires a higher API level, or a mix of old/new build tools.fixEnsure your `platforms/android/gradle.properties` file or `build.gradle` defines `compileSdkVersion` and `targetSdkVersion` appropriately for your AndroidX dependencies (e.g., API 28 or higher for many AndroidX features). This plugin helps with package migration, but version targets must still be correct.
Warnings
- gotcha Using `cordova-androidx-build` alongside `cordova-plugin-androidx-adapter` can lead to unpredictable build behavior and conflicts, as both aim to perform similar migration tasks but use different mechanisms. It's recommended to choose one based on your project requirements, especially regarding cloud build service compatibility.
- gotcha This plugin operates during the Gradle sync/build process, not during `cordova prepare`. This means that some AndroidX/Support Library conversion issues might only become apparent later in the build cycle compared to hook-script-based solutions.
- breaking While designed for compatibility, very old `cordova-android` versions (e.g., pre-8.x) may still exhibit issues when attempting to integrate with plugins requiring AndroidX, even with this plugin. The transition to AndroidX is best handled with `cordova-android@8.x` or newer.
Install
-
npm install cordova-androidx-build -
yarn add cordova-androidx-build -
pnpm add cordova-androidx-build
Quickstart
cordova plugin add cordova-androidx-build # Or, integrate as a dependency in your plugin.xml for other plugins: # (This allows your plugin to ensure the project is correctly configured for AndroidX) # <?xml version='1.0' encoding='utf-8'?> # <plugin id="my-awesome-plugin" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"> # <name>My Awesome Plugin</name> # <platform name="android"> # <dependency id="cordova-androidx-build" /> # <!-- Your plugin's Android specific source files and configurations --> # </platform> # </plugin> # After adding, simply build your Cordova project as usual: cordova build android