Here's my story: I've migrated my app to AndroidX because I needed some new features from a library I found online.
Problem: I'm currently running into some issues because I now need to develop a plugin for Cordova that implements a part of that app.
I generated a .arr file with my library & tried to make a Cordova plugin which acts as a interface to use the library. But when I try to use cordova-plugin-camera
with my plugin, which uses AndroidX, I get errors: duplicate imports because cordova-plugin-camera
uses the support library.
Solution: I've removed the dependencies to AndroidX & replaced them with the old support library.
Question: Is it a good idea to switch to AndroidX right now or am I better off keeping the support library ? Did I implement something wrong ? What did you choose for your projects ?
I've created a couple of utility plugins to assist with AndroidX migration in Cordova Android projects:
I created these as a generic solution for AndroidX support in my existing plugins which reference the Android Support Library, e.g. cordova-diagnostic-plugin against which AndroidX support issues has been raised.
This means that by installing both of these plugins in a Cordova project that already contains plugins which reference either the legacy Support Library names and/or the AndroidX names, the build will now succeed.
For example, try this test case:
cordova create test && cd test
cordova platform add android@8
cordova build android
=> build succeeds
cordova plugin add cordova.plugins.diagnostic@5
cordova build android
=> build succeeds
cordova plugin add cordova-plugin-androidx
cordova build android
=> build fails
cordova plugin add cordova-plugin-androidx-adapter
cordova build android
=> build succeeds
Just read that : https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html
To be sure :
Then :
Add the following in your config.xml :
<preference name="AndroidXEnabled" value="true" />
<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinCodeStyle" value="official" />
<preference name="GradlePluginKotlinVersion" value="1.3.50" />
(AndroidXEnabled preference add jetifyer and androidX in the gradle.properties)
And your build should now works
Btw @DaveAlden the https://github.com/dpa99c/cordova-plugin-androidx is messing up the gradle.properties file by adding multiples times the enable-jetifier and enableAndroidX rules instead of juste changing the bool values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With