apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

androidx #565

Closed janpio closed 4 years ago

janpio commented 5 years ago

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?

dpogue commented 5 years ago

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)

brodybits commented 5 years ago

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 commented 5 years ago

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

brodybits commented 5 years ago

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 commented 5 years ago

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:

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.

brodybits commented 5 years ago

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 https://github.com/apache/cordova-android/issues/565#issuecomment-440036712 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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

https://github.com/apache/cordova-plugin-camera/issues/405

brodybits commented 5 years ago

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 commented 5 years ago

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
brodybits commented 5 years ago

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

A few minor points so far:

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

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:

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).

brodybits commented 5 years ago

@davidschreiber I really appreciate your efforts to help resolve this issue, especially in https://github.com/apache/cordova-plugin-camera/pull/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 commented 5 years ago

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!

brodybits commented 5 years ago

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.

brodybits commented 5 years ago

@davidschreiber @steipete did you guys see dpa99c/cordova-plugin-androidx that @dpa99c posted in https://github.com/apache/cordova/issues/69#issuecomment-485553425?

From https://github.com/apache/cordova/issues/69#issuecomment-485553425 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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

I’ve installed it today for our app and so far it works great 👍

Sent from my iPhone

On 24. Apr 2019, at 7:35 PM, Dave Alden notifications@github.com wrote:

@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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Be4t5 commented 4 years ago

@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 commented 4 years ago

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:

https://github.com/apache/cordova-plugin-camera/issues/539 https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/489 https://github.com/apache/cordova-android/issues/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.

wf9a5m75 commented 3 years ago

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 :white_check_mark: :white_check_mark:
support library <- AndroidX :x: :white_check_mark:
work on PC :white_check_mark: :white_check_mark:
work on cloud services :x: :white_check_mark:
when execute the process after cordova prepare gradle sync
mechanism cordova hook script gradle