RuntimeException: Unable to get provider android.support.v4.content.FileProvider

My Android Studio build completes but the app keeps failing in the emulator and on devices with the following error (complete log follows, but here is the stated cause):

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/base.apk"],nativeLibraryDirectories=[/data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/lib/arm64, /data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]

Plugins

The only plugins I’m using are the following:

cordova-plugin-google-analytics (1.9.0)
cordova-sqlite-storage (5.0.0)
es6-promise-plugin (4.2.2)

Complete error message

Here’s the full output from logcat:

2020-05-15 16:28:02.956 9290-9290/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2020-05-15 16:28:02.959 9290-9290/? E/Zygote: accessInfo : 1
2020-05-15 16:28:02.975 9290-9290/? I/o.ionic.starte: Late-enabling -Xcheck:jni
2020-05-15 16:28:03.293 9290-9290/io.ionic.starter W/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
2020-05-15 16:28:03.294 9290-9290/io.ionic.starter I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
2020-05-15 16:28:03.294 9290-9290/io.ionic.starter D/AndroidRuntime: Shutting down VM
2020-05-15 16:28:03.296 9290-9290/io.ionic.starter E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.ionic.starter, PID: 9290
    java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/base.apk"],nativeLibraryDirectories=[/data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/lib/arm64, /data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:6770)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6312)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6227)
        at android.app.ActivityThread.access$1200(ActivityThread.java:238)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1787)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7073)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/base.apk"],nativeLibraryDirectories=[/data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/lib/arm64, /data/app/io.ionic.starter-X1v4RZ9YPITKm62O3C-xRQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:121)
        at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:67)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6754)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6312) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6227) 
        at android.app.ActivityThread.access$1200(ActivityThread.java:238) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1787) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7073) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
2020-05-15 16:28:03.306 9290-9290/? I/Process: Sending signal. PID: 9290 SIG: 9

I’m at a loss.

What is the version of capacitor that you are using? Is it 2.0.0+?

I had the same issue this morning because I was using version 2.1.0 and it requires androidx (jetpack). That being said, my guess is that some of your plugins are still using android versions prior to jetpack.

Specifying version ^1.5.2 to @capacitor/core @capacitor/cli @capacitor/android and @capacitor/ios did the trick for me.

You can also try cordova-plugin-androidx-adapter which is supposed to migrate all your native code to jetpack. However, it did not work on my end (ionic 4 + capacitor).

UPDATE
My issue was not exactly the same, but it was saying: could not find symbol android.support.v4.content.FileProvider

2 Likes

I’m using Capacitor 2.1.0. I installed and ran jetifier and updated gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

I guess my next step will be to try cordova-plugin-androidx-adapter, thanks!

Oh awesome! I tried jetifier as well, but it did not do anything (edit: I forgot the enableJetifier!! OOps!!). Let me know if it helps, because I would really love to do the same thing as you and use the latest version.

Jetifier is awesome though. It saved my life last summer when I was working with react native :slight_smile:

My pleasure and have a good day!

I installed the plugins…

npm install cordova-plugin-androidx
npm install cordova-plugin-androidx-adapter
ionic cap sync

… but I’m still getting the same error. :sob:

Guess the next step is to downgrade Capacitor. Thanks for the tip.

Yeah androidx-adapter was not working on my end as well :frowning:
Let me know what happens when you are on version ^1.5.2 I have been playing around with that kind of issue for the past week and I’ll see how I can help.

1 Like

Oh also I think you only need cordova-plugin-androix-adapter.

Also according to their documentation this plugin is using cordova hooks

And cordova hooks are not supported by capacitor. So it might be a reason why we cannot use this plugin properly.

1 Like

Ok, so I downgraded Capacitor and that didn’t work for me so I went back up to 2.1.0 (core, cli, and android platform), removed my android directory and reinstalled using npx cap add android, then in Android Studio, ran Refactor -> Migrate to AndroidX as described here (it gave me the message “no usages found” so that last step may or may not have done anything).

I also ended up running npm audit fix at some point, though I doubt that had anything to do with anything. But you never know.

Unfortunately, I wasn’t especially scientific about isolating the problem. If I had to guess, I think one of these were the cause:

  • version mismatch between @capacitor/android and @capacitor/core (now both are on 2.1.0)
  • some edit I made in AndroidManifest.xml or other file (I re-started the android project from scratch)

Anyway, my app seems to work now in both the emulator and physical devices.

Thanks for your insights @vitonimal, hope some of this info is helpful to you and others.

1 Like

Oh awesome! What were the changes made to the manifest?
And always a pleasure! glad you found the solution! :slight_smile:

@ebellempire thanks! I did follow your steps along with some modifications to my package.json:

changing @capacitor/cli @capacitor/core @capacitor/android and @capacitor/ios to 2.1.0
Most of my @ionic/native packages were on 5.0.0 beta and updated them to ^5.24.0

rrm -rf node_modules/
npm i
ionic build
npx cap add android
npx cap open android

I then followed the steps you provided to migrate the app project to AndroidX.

The build works :slight_smile:

Thanks a lot!

1 Like