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 support #69

Closed
brodybits opened this issue Jan 17, 2019 · 14 comments
Closed

androidx support #69

brodybits opened this issue Jan 17, 2019 · 14 comments
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed

Comments

@brodybits
Copy link

From discussion in apache/cordova-android#565 I think that androidx is not supported properly and needs to be improved. Described in a number of places including:

In short: androidx Java packages replace use of android Java packages for "unbundled" Java packages, meaning part of the SDK and not part of the Android system libraries. Use of old "unbundled" Java packages seems to be deprecated, obsolete.

I tried to explain in apache/cordova-android#565 that this should not be an issue with the Cordova Android platform itself. I think we will have to update at least some of the plugins, though.

I am flagging this as a bug at the top level due to usability issues that I think have started to come to light in apache/cordova-android#565, especially with the PSPDFKit.

I would personally like to see this resolved before we finish the Cordova 9 release (#10). This is my personal opinion for the sake of usability and not to be interpreted as the official position of Apache Cordova.

@brodybits brodybits added bug Something isn't working enhancement New feature or request help wanted Extra attention is needed labels Jan 17, 2019
@dpogue
Copy link
Member

dpogue commented Jan 17, 2019

I would personally like to see this resolved before we finish the Cordova 9 release (#10).

Correct me if we've discovered otherwise, but I believe there is nothing to resolve at the cordova-android level, and therefore nothing that would delay Cordova 9. The changes for Android X need to happen in new major versions of the plugins, which is beyond the scope of the Cordova 9 release.

@jcesarmobile
Copy link
Member

jcesarmobile commented Jan 17, 2019

Well, I did a quick read and it looks like it just needs to target SDK 28, which I think it's already there. (I noticed this file still references 27, but not sure if it's used anymore https://github.com/apache/cordova-android/blob/master/framework/project.properties#L13)

And set two values to true in a gradle.properties file, which I can't find on Cordova projects, so not sure if we want to create it as default or leave the users do it themselves (probably not as it should go in projectName/platforms/android/ and everything there will be wiped).

Also we should try and see what happens when some plugins use the new "support library", and others the old one

@brodybits
Copy link
Author

(I noticed this file still references 27, but not sure if it's used anymore https://github.com/apache/cordova-android/blob/master/framework/project.properties#L13)

I think that needs to be updated, will raise a PR with a better explanation.

@dpa99c
Copy link

dpa99c commented Apr 13, 2019

The changes for Android X need to happen in new major versions of the plugins, which is beyond the scope of the Cordova 9 release.

@dpogue I think this presents a problem for plugin authors such as myself since it is up to the Cordova project owner/plugin user as to whether they optionally enable AndroidX by manually adding the required properties to gradle.properties (see dpa99c/cordova-diagnostic-plugin#350).

A reason they may choose not to enable AndroidX is that other 3rd-party Cordova plugins on which their project depends have not been updated for AndroidX - many popular 3rd party plugins are poorly maintained.

Therefore a new major plugin version that is updated for AndroidX will be ununsable in projects which have not been configured to use AndroidX: I can foresee a flood of issues opened against my plugins along the lines of "AndroidX support broke my Cordova Android builds".

If the next major version of cordova-android configured AndroidX to be enabled by default, this would be less of an issue because plugin authors could use <engines> in the plugin.xml to restrict the new major plugin version to a minimum of that latest version of cordova-android.

In the meantime, I'm considering whether I can create a hook script which runs on plugin installation and depends on a plugin variable (i.e. ANDROIDX_ENABLED=true|false) which would dynamically replace the relevant class names in the Java source code and the <framework> elements in the plugin.xml.
This would enable a single version of my plugins to run both with or without AndroidX.

@dpa99c
Copy link

dpa99c commented Apr 22, 2019

I've implemented a generic solution for AndroidX support in my plugins which reference the Android Support Library by creating a couple of new plugins:

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

@jcesarmobile
Copy link
Member

wow, this is amazing, thanks @dpa99c!

@wf9a5m75
Copy link

Since the some users of my plugin use PhoneGap Build which does not support hook scripts, @dpa99c 's solution does not work. (And they always report to me)

I think most cloud build services do not support cordova hook scripts due to the security reason.

@jcesarmobile
Copy link
Member

As far as I know only Phonegap Build doesn't support hooks.

The Android X support is ready, we just need to release cordova-android 9

But doesn't look like Phonegap Build is doing more updates in their servers, so the cordova-android 9 release won't help you. Check the adobe forums and you'll see dozens of topics about the iOS 13 SDK requirements not met by Phonegap Build and no official answer.

@wf9a5m75
Copy link

wf9a5m75 commented May 30, 2020

As we discuss 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.

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

@almothafar
Copy link

@wf9a5m75 sadly, it is not working:


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
  The following AndroidX dependencies are detected: androidx.appcompat:appcompat:1.1.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.versionedparcelable:versionedparcelable:1.1.0, androidx.fragment:fragment:1.1.0, an
droidx.core:core:1.2.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.constraintlayout:constraintlayout-solver:1.1.3, androidx.interpolator:interpolator:1.0.0, androidx.loader:l
oader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.activity:activity:1.0.0, androidx.collection:collection:1.1.0, androidx.viewpager:viewpager:1.0.0, androidx.cardview:cardview:1.0.0, androidx.localbroadcastmanager:loca
lbroadcastmanager:1.0.0, androidx.arch.core:core-common:2.1.0, androidx.savedstate:savedstate:1.0.0, androidx.annotation:annotation:1.1.0, androidx.lifecycle:lifecycle-common:2.1.0, androidx.appcompat:appcompat-resources:1.1.0, andr
oidx.lifecycle:lifecycle-livedata:2.0.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-viewmodel:2.1.0, androidx.constraintlayout:constraintlayout:1.1.3, androidx.lifecycle:lifecycle-livedata-core:2.0.0,
 androidx.browser:browser:1.0.0, androidx.legacy:legacy-support-v4:1.0.0, androidx.media:media:1.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0,
androidx.cursoradapter:cursoradapter:1.0.0, androidx.vectordrawable:vectordrawable-animated:1.1.0, androidx.lifecycle:lifecycle-runtime:2.1.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclay
outinflater:1.0.0, androidx.vectordrawable:vectordrawable:1.1.0, androidx.print:print:1.0.0


Still getting this.

@dpa99c
Copy link

dpa99c commented Sep 22, 2020

@almothafar have you set the preference in config.xml as outlined in the cordova-android@9.0.0 release annnouncement?

<preference name="AndroidXEnabled" value="true" />

@dpa99c
Copy link

dpa99c commented Sep 22, 2020

BTW @brodybits can this be closed as cordova-android@9 now supports AndroidX?

@jcesarmobile
Copy link
Member

Yeah, closing since AndroidX is now supported.

There are some ongoing conversations about making the platform androidX only for next release or as an independent platform on this issue

It was also mentioned on an online meetup we did a few weeks ago see recording

@almothafar
Copy link

@dpa99c oh my bad, I totally forgot that, do I need to install "cordova-androidx-build" as well? or not necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants