Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

androidx #565

Closed
janpio opened this issue Nov 18, 2018 · 22 comments · Fixed by #901
Closed

androidx #565

janpio opened this issue Nov 18, 2018 · 22 comments · Fixed by #901
Labels
info-needed / awaiting response Further information is requested

Comments

@janpio
Copy link
Member

janpio commented Nov 18, 2018

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?

@brodycj brodycj added the info-needed / awaiting response Further information is requested label Nov 19, 2018
@dpogue
Copy link
Member

dpogue commented Nov 19, 2018

The short answer is no, at least for now. The existing support library will continue to exist for the foreseeable future, so cordova-android should be fine.

However, we should probably look into migrating to AndroidX with a major version bump. We can't do it sooner, because AndroidX is only available when targeting Android 9 and higher.

Also worth noting that there's an AndroidX WebView compatibility library, but we can't use it until we drop support for Android 4.4 (which is not happening in the next major)

@brodycj
Copy link

brodycj commented Nov 19, 2018

I did take a look, started composing an answer while working on something else.

My impression from https://android-developers.googleblog.com/2018/05/hello-world-androidx.html is that androidx is only used for "unbundled" Java package namespaces (Java packages), meaning part of the SDK and not part of the Android system libraries. The Java code only seems to use the affected Java packages in test/app/src/androidTest, which I think should not affect any Cordova Android app developers in case we or they decide to use AndroidX someday.

(My trick was to search all Java files in cordova-android for "import com.android", "import android.arch", "import android.databi", and "import android.supp", according to affected namespaces described in https://developer.android.com/jetpack/androidx/migrate)

@dpogue
Copy link
Member

dpogue commented Nov 19, 2018

Some plugins (i.e., camera) have to use the support library for dealing with FileProviders

@brodycj
Copy link

brodycj commented Nov 19, 2018

Would this be more plugin-specific then?

I wonder if we could support AndroidX vs old style in a separate plugin for a while?

@davidschreiber
Copy link

davidschreiber commented 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.

@brodycj
Copy link

brodycj commented Jan 16, 2019

We're currently getting reports of Cordova users that fail to upgrade due to the lack of AndroidX support in cordova-android.

@davidschreiber it would really help if you could explain what exactly is going wrong. I tried to explain in #565 (comment) that none of the code in this project (cordova-android) should be affected by the androidx updates. The one possible exception is some testing code in test/app/src/androidTest, which should not be part of the generated Cordova Android project.

I took a quick look through README.md in https://github.com/PSPDFKit/Cordova-Android and noticed that it needs the nightly release of cordova-android@8. You can see in apache/cordova#10 that we are in the process of finishing and releasing the Cordova 9 major release so that your users will no longer need the nightly release.

@davidschreiber
Copy link

davidschreiber commented Jan 17, 2019

Hi @brodybits. Thanks for the feedback. You're absolutely right that this is not a specific issue to the code inside cordova-android but relevant for the next major version bump of Cordova plugins. However, since AndroidX only affects the Android parts of Cordova, I took the chance to comment on this existing issue, which seemed to me like an "umbrella issue" for the general migration topic. I'm sorry for any confusion this might have caused.

@davidschreiber it would really help if you could explain what exactly is going wrong.

The specific issue our customers are facing is a D8 build time error which comes from including Cordova plugins that still use the support libraries (in this specific case the cordova-plugin-camera) while also including plugins that contain AndroidX libraries. As you mentioned, this is not specific to code inside android-cordova.

I took a quick look through README.md in https://github.com/PSPDFKit/Cordova-Android and noticed that it needs the nightly release of cordova-android@8. You can see in apache/cordova#10 that we are in the process of finishing and releasing the Cordova 9 major release so that your users will no longer need the nightly release.

Thank you very much for the heads-up. It's great to hear that the update to Cordova 9 is progressing well, and we're looking forward to the stable release of it.

I'm sorry if I misunderstood the scope of Cordova 9. Do I now understand it correctly, that major releases of cordova and cordova-android are not strictly tied to upgrades of the official plugins? If that is the case, I would go ahead and create AndroidX migration issues in the specific plugin repos (and probably also prepare PRs if this is desired).

@janpio
Copy link
Member Author

janpio commented Jan 17, 2019

Do I now understand it correctly, that major releases of cordova and cordova-android are not strictly tied to upgrades of the official plugins? If that is the case, I would go ahead and create AndroidX migration issues in the specific plugin repos (and probably also prepare PRs if this is desired).

Yes + Yes please!

@jcesarmobile
Copy link
Member

@brodycj
Copy link

brodycj commented Jan 28, 2019

The specific issue our customers are facing is a D8 build time error which comes from including Cordova plugins that still use the support libraries (in this specific case the cordova-plugin-camera) while also including plugins that contain AndroidX libraries.

I would be grateful if someone could post a demo project. I already spent almost half a day without success using AndroidX from a Cordova-Android project.

@davidschreiber
Copy link

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: apache/cordova-plugin-camera#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

@brodycj
Copy link

brodycj commented Jan 30, 2019

Thanks @davidschreiber. I was able to reproduce a successful build with AndroidX using PSPDFKit/Cordova-Android (latest release) and no other plugins as follows:

  • create new Cordova project: cordova create cbtest1
  • cd cbtest1
  • cordova plugin add https://github.com/PSPDFKit/Cordova-Android#5.1.1 (latest version so far)
  • cordova platform add android@8.0.0-nightly.2019.1.30.54df4a11
  • add the evaluation license info to platforms/android/local.properties, as given above by @davidschreiber
  • cordova build android -- --gradleArg=-PcdvCompileSdkVersion=android-28

A few minor points so far:

  • I used specific nightly and GitHub tags for the sake of maximum reproducibility, in a similar fashion to the steps given above.
  • I ignored some D8 warning messages since I did not configure D8 as described above.
  • My build stopped at pspdfkit-demo-5.1.1.aar due to an issue with my internet connection. When I retried the same build command then it continued successfully.

Here is how I reproduced the build failure with AndroidX and the old Support Library:

  • I made a new test project with plugin from https://github.com/PSPDFKit/Cordova-Android#5.1.1 (it should be good enough to just remove the platforms directory)
  • cordova plugin add cordova-plugin-camera@4.0.3 (latest version to date)
  • cordova platform add android@8.0.0-nightly.2019.1.30.54df4a11 (same as above)
  • copy the evaluation license info to platforms/android/local.properties, as given above by @davidschreiber
  • cordova build android -- --gradleArg=-PcdvCompileSdkVersion=android-28 --gradleArg=--stacktrace

I got the following build failure output:

:app:transformClassesWithMultidexlistForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

Here is how I reproduced a working AndroidX build with PSPDFKit/Cordova-Android and apache/cordova-plugin-camera#418:

  • removed the existing Android build project (rm -rf platforms)
  • cordova plugin add https://github.com/davidschreiber/cordova-plugin-camera\#davidschreiber/androidx-migration (as given above by @davidschreiber)
  • cordova platform add android@8.0.0-nightly.2019.1.30.54df4a11 (same as above)
  • copy the evaluation license info to platforms/android/local.properties, as given above by @davidschreiber
  • cordova build android -- --gradleArg=-PcdvCompileSdkVersion=android-28 --gradleArg=--stacktrace

As a next step I hope we can find an easier way to reproduce the failure with AndroidX due to the conflict with plugins using the old support library. I hope to work on it soon, cannot make any promises right now.

I hope we can get this resolved in the Apache Cordova plugins before we finish the Cordova 9 release (apache/cordova#10).

@brodycj
Copy link

brodycj commented Jan 31, 2019

@davidschreiber I really appreciate your efforts to help resolve this issue, especially in apache/cordova-plugin-camera#418. I am very sorry that it has not proven to be so easy to resolve the issue with AndroidX in Cordova.

I think you pointed out a very important issue with the compile SDK version (#631), which should be resolved before we continue with AndroidX support.

I cannot promise when I will get a chance to resolve #631 due to some other priorities and commitments.

@steipete
Copy link

steipete commented Apr 6, 2019

Hi! Just checking on the status of AndroidX and the Cordova ecosystem.
Are there any guidelines or roadmap plans by now? (I'd like to relay that to one of our partners that use our wrapper). Thanks!

@brodycj
Copy link

brodycj commented Apr 8, 2019

New Cordova 9 release has been shipped.

As discussed before, the only possible issue with AndroidX is in the plugins. I think it would be good to get this resolved before we ship the major release of the plugins.

The one plugin where I could see this issue is cordova-plugin-camera. Someone has already raised a PR in apache/cordova-plugin-camera#418 but it seems to be waiting for some rework.

I personally do not have so much time to work on this issue due to some other priorities.

@brodycj
Copy link

brodycj commented Apr 24, 2019

@davidschreiber @steipete did you guys see dpa99c/cordova-plugin-androidx that @dpa99c posted in apache/cordova#69 (comment)?

From apache/cordova#69 (comment) it sounds like dpa99c/cordova-plugin-androidx may be needed to work reliably with AndroidX. I would love some more feedback if this proves to be the case or not.

I wonder if we should integrate the changes from dpa99c/cordova-plugin-androidx into cordova-android someday?

@dpogue
Copy link
Member

dpogue commented Apr 24, 2019

I think I agree with the idea that the next major version of Android should be set up to use AndroidX in gradle, and all plugins using Android Support Libraries should be migrated to AndroidX.

@dpa99c
Copy link

dpa99c commented Apr 24, 2019

@dpogue Until such time as plugin authors have updated their plugins to migrate to AndroidX, it should be possible to use cordova-plugin-androidx-adapter to migrate their legacy plugin code in-place inside a Cordova Android project.

@timbru31
Copy link
Member

timbru31 commented Apr 24, 2019 via email

@Be4t5
Copy link

Be4t5 commented Jun 18, 2019

@dpogue Until such time as plugin authors have updated their plugins to migrate to AndroidX, it should be possible to use cordova-plugin-androidx-adapter to migrate their legacy plugin code in-place inside a Cordova Android project.

Thank you! You are a lifesaver! I was going to start editing each plugin by hand and I found your message :) :)

@florianmonfort
Copy link

florianmonfort commented Dec 16, 2019

Hi all,

It seems a lot of plugins still have issues despite the androidx plug in that @dpa99c has created. The problem is these plugins are used for critical functions of our app and we can't get Android Studio to compile or even within the command line. I have opened bug reports in each of the different repositories for this but besides that we have found no solution and we can't publish any new app updates anymore and don't know what to do:

apache/cordova-plugin-camera#539
ionic-team/cordova-plugin-ionic-webview#489
#881

There is also some weird issue where after adding android to the cordova platforms every time we open with Android Studio there is an issue with the gradle file having some weird 27.+ line that gradle doesn't like. We also have no idea why cordova does this and haven't found any info anywhere.

If @Be4t5 , @timbru31 @brodybits have any suggestions on how to fix this it would be highly appreciated.

Oh and as a side note in case this is useful information: we did not have these issues before moving to Cordova Android 8.x versions. Everything was compiling correctly.

@erisu erisu mentioned this issue Jan 20, 2020
3 tasks
@wf9a5m75
Copy link

cordova-plugin-androidx-adapter does not work on PhoneGap build. It means this solution is not perfect for me.

That's why I re-created another plugin, which is written in gradle script.
cordova-androidx-build

The purpose of this plugin is little different from cordova-plugin-androidx-adapter.
cordova-plugin-androidx-adapter migrates the project code from Android Support Libraries to AndroidX libraries, which is one way.
This is OK for general developers.

However plugin developers have to support both environments for a while (cordova-android@8 and cordova-android@9).

That's why this plugin migrates from AndroidX libraries to Android Support Libraries if the environment does not support AndroidX.

work-flow

And this plugin uses Gradle script, works on PC and cloud services.
If you are interested in, please try it

cordova-plugin-androidx-adapter cordova-androidx-build
support library -> AndroidX
support library <- AndroidX
work on PC
work on cloud services
when execute the process after cordova prepare gradle sync
mechanism cordova hook script gradle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed / awaiting response Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.