Closed timbru31 closed 1 year ago
Good news! dpa99c just released two plugins, one to enable AndroidX support, one to fill in the compatibility gap: https://github.com/dpa99c/cordova-diagnostic-plugin/issues/350#issuecomment-485551917
hi @timbru31 thanks that's great news! I will try to look into that comment and merge the changes back in here.
Hi is there any news on this issue?
You can use the cordova-plugin-androidx-adapter and cordova-plugin-androidx plugins in the meantime to solve this issue
that solved it for me, thank you
@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?
No, I just installed the 2 plugins, that took care of it for me
The plugins do two things:
As a plugin author, I'd do the following:
Users should be able to either just use cordova-android@9 or cordova-android@8 with cordova-plugin-androidx.
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.
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.
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.
@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.
The plugins do two things:
- cordova-plugin-androidx enables the AndroidX support in the gradle files: https://github.com/dpa99c/cordova-plugin-androidx/blob/master/scripts/apply-to-gradle.properties.js#L31-L36
- cordova-plugin-androidx-adapter replaces all v4 occurrences with the AndroidX equivalent (https://github.com/dpa99c/cordova-plugin-androidx-adapter/blob/master/apply.js#L38-L54) - since Cordova plugins are shipping .java files instead of .class files, the Android Jettifier can't do this automatically.
As a plugin author, I'd do the following:
- Wait until cordova-android@9 is released with AndroidX support out of the box (apache/cordova-android#901)
- Upgrade my plugin code to use only AndroidX
- 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
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?
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.
Any update or better fork for this?
@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!
@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 !
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 :)
@richardkshergold did you ever solve this for AppFlow? Am experiencing the same issue. Build manually works with the jetifier plugin etc but AppFlow fails
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.
@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
Expected Behaviour
The plugin is compatible with AndroidX (as discussed here: https://github.com/pwlin/cordova-plugin-file-opener2/issues/251#issuecomment-467488576)
Actual Behaviour
Plugin is not compatible with AndroidX.
Reproduce Scenario (including but not limited to)
Steps to Reproduce
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
Here is the output:
n/a
Plugin version
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 toandroidx.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.