question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Just learned about androidx, this new package name Google uses or will use for support libraries and similar stuff:

https://stackoverflow.com/questions/51280090/what-is-androidx https://developer.android.com/jetpack/androidx/

Will this affect cordova-android?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:22 (14 by maintainers)

github_iconTop GitHub Comments

19reactions
davidschreibercommented, Jan 16, 2019

Hi there 👋I’d like to better understand the current schedule for the AndroidX migration of cordova-android.

We (the team at PSPDFKit, and maintainers of PSPDFKit/Cordova-Android) have previously upgraded our Android library to AndroidX (as many of our customers did with their apps and libraries too). We’re currently getting reports of Cordova users that fail to upgrade due to the lack of AndroidX support in cordova-android. We’ve performed a brief analysis of the current situation, and thought it might be interesting for you as well.

There’s a couple of factors that should be considered for your schedule for migrating to AndroidX:

  • Development of the support libraries has been halted and the old support libraries have officially been deprecated. In the next couple of weeks/months, most Android libraries and apps that used the support libs will migrate to AndroidX (if they haven’t done so already). The incompatibility we discovered with our own wrapper is probably just the beginning, and cordova-android will have to follow this trend to stay compatible with the Android ecosystem. A migration has to happen, the question is when it should be done.

  • Moving to AndroidX is a breaking change for Cordova, so it should probably be part of the next major update (9.x). While for normal Android apps upgrading to AndroidX is a soft-migration (using Google’s automated Jetifier migration which auto-migrates old .class files that use the support libs over to AndroidX) this migration strategy does not work for Cordova, which is built around plugins that ship as .java source files. Jetifier was not designed for such a plugin system, and does not operate on source files, which means that all Cordova plugins need to be migrated manually in order to work.

  • Integrating AndroidX and the support libraries into a single app does not work. While most classes inside AndroidX have been renamed and are now inside the androidx.* package, some legacy code is still inside the old support package names, which will cause build errors when trying to integrate both libraries side by side.

  • Migration to AndroidX will require updates to the Android part of several official Cordova plugins. I don’t have an extensive list of plugins that use the support libs yet, but I believe that the effort to migrate these should be manageable. From our experience, migrating works automatic for most parts using Android Studio, or is a matter of search and replace using any other tool.

Are there any concrete plans for migration to AndroidX so far, and if so, could you share them with us? Any feedback would be highly appreciated.

4reactions
davidschreibercommented, Jan 30, 2019

I created a small sample project by following these steps:

cordova create cordova-example2 com.pspdfkit.cordovaexample cordova-example
# Brings in AndroidX
cordova plugin add https://github.com/PSPDFKit/Cordova-Android/
# Brings in the Support Library
cordova plugin add cordova-plugin-camera
# Required for building PSPDFKit
cordova platform add android@8.0.0-nightly.2018.11.23.ef243418

In order to build the project, you need to bump compile target to 28 and add a Maven key and License for building PSPDFKit.

Add this to platforms/android/local.properties. It’s an evaluation license of PSPDFKit:

pspdfkit.password=TRIAL-Z5d2Z7Ftr4ZQADAIwysuZ92Algq5fGJnJTZfNJgP0eSDGZBR0Gmc-8X65tQ2d6FtqmfU4bWfSm39uheDddwpXw
pspdfkit.license=I-N0J9nyZmqpre3nBv5Y5w9UxiuEYDIvY8GLUFBvD1-NlDxjLMSwXhgcd8zC6XdIy53divvD9BZfvZYERS2xV9tW7rFChXglO7m8XdzZEIWv94vspD_LY4X-6S6HucpgLkvl0nbjnEZdy1Nz5hv4Ek_p80Ilwin2dCBxQiJaH32H85U7vsL_hfXLZGEClHisNSnMAOVgdbEIZRttegjADstK0UDSqXoUDkrIUWmyeg_SqcnPDpEVGTg5URsnvzc3gdbzdsEnnslSfsSqKzU7OAQ78MtOHBbkZsLyQc0mlxLCU44NcLUE_6XGq2gdLae-aDafbnUNOqhXmB4kkwfuAWrSIApyU3jj7Bfrsa0HINPgkCIrjaTBW8izE69JlbFB5wRKKOoALXQiMqAJALg_DYKD7zCbyj5ES_k3mRzOmttxyGsCzognYVXGnq1c0Tr5

Change content of platforms/android/gradle.properties to this. This will set the correct compile SDK version and will prepare the project for building:

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m
android.useDeprecatedNdk=true

cdvCompileSdkVersion=android-28
cdvBuildToolsVersion=28.0.3
android.enableD8=true

You can now run the build, which will fail due to a conflict between AndroidX and the Support Library:

cordova build android -- --gradleArg=--stacktrace

In order to check that migrating the plugin to AndroidX works, I’ve created a small PR that actually migrates the plugin: https://github.com/apache/cordova-plugin-camera/pull/418.

By swapping out the plugin with my PR version, you can verify that the migration works:

corcova plugin remove cordova-plugin-camera
cordova plugin add https://github.com/davidschreiber/cordova-plugin-camera\#davidschreiber/androidx-migration
cordova build android -- --gradleArg=--stacktrace
Read more comments on GitHub >

github_iconTop Results From Across the Web

AndroidX Overview - Android Developers
AndroidX is a major improvement to the original Android Support Library, which is no longer maintained. androidx packages fully replace the ...
Read more >
androidx-main - GitHub
Development environment for Android Jetpack extension libraries under the androidx namespace. Synchronized with Android Jetpack's primary development branch ...
Read more >
android - What is AndroidX? - Stack Overflow
AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS ...
Read more >
What is AndroidX Library in Android? - GeeksforGeeks
The Android Extension Library, often known as AndroidX, is the new open-source project that is a significant upgrade to the original Android ...
Read more >
What Is AndroidX? - Better Programming
First things first. AndroidX stands for Android E X tension Libraries. This simple denotation makes it clearer for an experienced developer what's behind...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found