Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidX transition and Cordova, what are the risks/benefits?

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 ?

like image 375
Noxilex Avatar asked Apr 02 '19 13:04

Noxilex


2 Answers

I've created a couple of utility plugins to assist with AndroidX migration in Cordova Android projects:

  • cordova-plugin-androidx will persistently configure a Cordova Android platform project to use AndroidX.
  • cordova-plugin-androidx-adapter migrates any references to the legacy Support Library in a Cordova Android platform project to use the AndroidX equivalent names.

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
like image 85
DaveAlden Avatar answered Nov 23 '22 05:11

DaveAlden


Just read that : https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html

To be sure :

  • Clear your gradle cache directory (in home/.gradle/caches)
  • Remove and add the android platform
  • Check your requirement following the above article ones

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)

  • Add the https://www.npmjs.com/package/cordova-plugin-androidx-adapter plugin.
  • Then prepare the android platform

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

like image 31
Lucas Avatar answered Nov 23 '22 05:11

Lucas