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

Closed
timbru31 opened this issue Apr 10, 2019 · 23 comments
Closed

AndroidX support #256

timbru31 opened this issue Apr 10, 2019 · 23 comments
Assignees
Labels
enhancement help-needed need help developing, using, testing this plugin

Comments

@timbru31
Copy link

Expected Behaviour

The plugin is compatible with AndroidX (as discussed here: #251 (comment))

Actual Behaviour

Plugin is not compatible with AndroidX.

Reproduce Scenario (including but not limited to)

Steps to Reproduce

  1. Install the plugin and build it for Android.
  2. As cordova-android does not yet support AndroidX (see androidx apache/cordova-android#565), open the project manually with Android Studio.
  3. Manually migrate to AndroidX (see https://developer.android.com/jetpack/androidx/migrate#migrate)
  4. The refactoring has to be done manually:

image

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

n/a

Cordova CLI info

cordova info

Here is the output:

n/a

Plugin version

cordova plugin version | grep cordova-plugin-file-opener2

Here is the output:

2.2.0

Sample Code that illustrates the problem

The current code [...] extends android.support.v4.content.FileProvider {
needs to be updated to androidx.core.content.FileProvider.

This is a breaking change and will require a major version bump.

Logs taken while reproducing problem

n/a

Background info

Sadly, since Cordova plugins ship the .java instead of the .class files the automatic migration (jettifier, see: https://developer.android.com/jetpack/androidx#using_androidx) does not work and the plugin authors need to update their plugins.

@shnist shnist pinned this issue Apr 15, 2019
@pwlin pwlin unpinned this issue Apr 16, 2019
@shnist shnist pinned this issue Apr 23, 2019
@timbru31
Copy link
Author

Good news! dpa99c just released two plugins, one to enable AndroidX support, one to fill in the compatibility gap: dpa99c/cordova-diagnostic-plugin#350 (comment)

@pwlin
Copy link
Owner

pwlin commented Apr 26, 2019

hi @timbru31 thanks that's great news! I will try to look into that comment and merge the changes back in here.

@mg
Copy link

mg commented Sep 19, 2019

Hi is there any news on this issue?

@timbru31
Copy link
Author

You can use the cordova-plugin-androidx-adapter and cordova-plugin-androidx plugins in the meantime to solve this issue

@mg
Copy link

mg commented Sep 19, 2019

that solved it for me, thank you

@pwlin
Copy link
Owner

pwlin commented May 13, 2020

@timbru31, @mg How do you go solving this issue? I have looked into the plugin mentioned but I am not sure what do you. Is this just a matter of changing the FileProvider class to extend androidx.core.content.FileProvider, instead of android.support.v4.content.FileProvider? I appreciate your suggestions.

Update: Is #292 something that would completely fix this issue?

@mg
Copy link

mg commented May 13, 2020

No, I just installed the 2 plugins, that took care of it for me

@timbru31
Copy link
Author

The plugins do two things:

As a plugin author, I'd do the following:

  1. Wait until cordova-android@9 is released with AndroidX support out of the box (feat: add androidx support apache/cordova-android#901)
  2. Upgrade my plugin code to use only AndroidX
  3. Release a new major version which requires cordova-android@9

Users should be able to either just use cordova-android@9 or cordova-android@8 with cordova-plugin-androidx.

@timbru31
Copy link
Author

Update: Is #292 something that would completely fix this issue?

This forces all your users to install two plugins from another author or wait until cordova-android@9 is released - or breaks the plugin for them in case they can't migrate to AndroidX (yet).
But yes, technically it would close this issue.

@pwlin
Copy link
Owner

pwlin commented May 14, 2020

Thank you for the explanation. I think at the moment the best way to handle this is to add cordova-plugin-androidx and cordova-plugin-androidx-adapter to one's project. I will add a note to readme.md about how to support AndroidX, linking to those 2 plugins.

@StefanVanStaden
Copy link

Hi, I am having this issue as well but I am using Capacitor not Cordova. So I installed cordova-plugin-androidx and cordova-plugin-androidx-adapter using npm and when I synced with the Android project it still came up with the issue. Every time I make a build I need to manually change

public class FileProvider extends android.support.v4.content.FileProvider { }

to the following

public class FileProvider extends androidx.core.content.FileProvider { }

I would imagine this change will be required for anyone who keeps there projects up to date with the latest technology. If not then they simply need to use the lock file and lock this package to where they need it. I will not be able to compile my application using CI/CD since I will need to manually come and change this code after every Ionic build.

@davidmarquis
Copy link

@StefanVanStaden Looks like using Jetifier with Capacitor has cut it for me. I just followed the instructions here: https://capacitorjs.com/docs/android/troubleshooting#error-package-android-support-does-not-exist

In short, I ran:

npm install jetifier
npx jetify
npx cap sync android

And the subsequent automated builds ran correctly.

@vikshv
Copy link

vikshv commented Aug 20, 2020

The plugins do two things:

As a plugin author, I'd do the following:

  1. Wait until cordova-android@9 is released with AndroidX support out of the box (apache/cordova-android#901)
  2. Upgrade my plugin code to use only AndroidX
  3. Release a new major version which requires cordova-android@9

Users should be able to either just use cordova-android@9 or cordova-android@8 with cordova-plugin-androidx.

Cordova 10.0.0 released with cordova-android@9.0.0: https://cordova.apache.org/announcements/2020/07/28/cordova-lib-release-10.0.0.html

Now my build failed with cordova@10.0.0 and cordova-android@9.0.0. Required android.support.v4.content

AndroidXEnabled = true

@richardkshergold
Copy link

When I build my Ionic 5 Capacitor app locally the app builds ok but when I build up on AppFlow the build fails with the error

android.support.v4.content does not exist against the FileOpener2 plugin.

The ionic docs suggest adding jetifier and running npx jetify so I have installed it and added the following to the package.json scripts section:

"postinstall": "npx jetify"

Unfortunately the builds still fail on AppFlow with an error of:

npm WARN lifecycle myApp@2.9.9~postinstall: cannot run in wd myApp@2.9.9 npx jetify (wd=/builds/myName/myApp)

I then tried with these two plugins instead (as per the docs):

cordova-plugin-androidx
cordova-plugin-androidx-adapter

However when I add these and try to build on AppFlow I get a failure with the original error again:

android.support.v4.content does not exist

Does this mean I am not going to be able to use this plugin with AppFlow?

@almothafar
Copy link

It is a blocked issue for me now!

> Task :app:compileReleaseJavaWithJavac FAILED
/app/platforms/android/app/src/main/java/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java:28: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {
                                                            ^
/app/platforms/android/app/src/main/java/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java:119: error: cannot find symbol
                                                path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".fileOpener2.provider", file);
                                                                   ^
  symbol:   method getUriForFile(Context,String,File)
  location: class FileProvider
/app/platforms/android/app/src/main/java/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java:127: error: cannot find symbol
                                        Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".fileOpener2.provider", file);
                                                               ^
  symbol:   method getUriForFile(Context,String,File)
  location: class FileProvider
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors

FAILURE: Build failed with an exception.

@almothafar
Copy link

Any update or better fork for this?

@patriciopage
Copy link

@StefanVanStaden Looks like using Jetifier with Capacitor has cut it for me. I just followed the instructions here: https://capacitorjs.com/docs/android/troubleshooting#error-package-android-support-does-not-exist

In short, I ran:

npm install jetifier
npx jetify
npx cap sync android

And the subsequent automated builds ran correctly.

This worked for me. Without installing the androidx plugins (cordova-plugin-androidx and cordova-plugin-androidx-adapter) I ran those three commands and now my FileProvider class from cordova FileOpener2 extends androidx.core.content.FileProvider.

Thanks!

@tshesko1
Copy link

@StefanVanStaden Looks like using Jetifier with Capacitor has cut it for me. I just followed the instructions here: https://capacitorjs.com/docs/android/troubleshooting#error-package-android-support-does-not-exist
In short, I ran:

npm install jetifier
npx jetify
npx cap sync android

And the subsequent automated builds ran correctly.

This worked for me. Without installing the androidx plugins (cordova-plugin-androidx and cordova-plugin-androidx-adapter) I ran those three commands and now my FileProvider class from cordova FileOpener2 extends androidx.core.content.FileProvider.

These 3 lines of codes from https://capacitorjs.com/docs/android/troubleshooting#error-package-android-support-does-not-exist
just saved my projects. Thank You !

@almothafar
Copy link

Running npx jetify in ionic cordova project solved my issue, just before I build the app.

@richardkshergold you seems found your solution here: https://forum.ionicframework.com/t/android-support-v4-content-does-not-exist-appflow-build-issue/194978 just need to link this thread :)

@KirstenStake
Copy link

@richardkshergold did you ever solve this for AppFlow? Am experiencing the same issue. Build manually works with the jetifier plugin etc but AppFlow fails

@richardshergold
Copy link

richardshergold commented Sep 30, 2021

Hi Kirsten. Yes I did with the help of an Ionic engineer. The solution was to place a .npmrc file in the root of the project with the following in it:

unsafe-perm=true

I hope that works for you too.

@KirstenStake
Copy link

@richardshergold thank you for your speedy reply.

for anyone else, to summarise entire steps:

As a workaround, you can patch the plugin using jetifier:

npm install jetifier
npx jetify
npx cap sync android

The jetifier should be in package.json file.

You need to include a postinstall script in package.json for jetifier to run. This can be done as shown below:

"scripts": {
...
"postinstall": "jetifier"
}

In the file named .npmrc (create the file if not already present) in the root of your project, add the following contents. This will give npm running the jetifier script permissions.
unsafe-perm=true

@shnist
Copy link
Collaborator

shnist commented Jan 31, 2023

androidX is now supported in the latest release

@shnist shnist closed this as completed Jan 31, 2023
@shnist shnist unpinned this issue Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help-needed need help developing, using, testing this plugin
Projects
None yet
Development

No branches or pull requests