Application error after reinstalling on emulator because FileProvider class was not found

When I run the application on the emulator, it always works on the first try. But when the application is already installed on the emulator, this often leads to a crash during application startup. This behavior started with Android Studio 2.0. This does not happen on devices, so it is not so important, but only annoying, since I always need to remove the application from the emulator before installing the new version.

Since I absolutely do not know what causes this problem, and cannot find similar problems during the study, I hope someone can help me.

Error message:

08-25 09:55:35.023 4214-4214/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mls.Search.Abbott, PID: 4214 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/com.mls.Search.Abbott-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mls.Search.Abbott-2/lib/x86, /data/app/com.mls.Search.Abbott-2/base.apk!/lib/x86, /vendor/lib, /system/lib]] at android.app.ActivityThread.installProvider(ActivityThread.java:5156) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.mls.Search.Abbott-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mls.Search.Abbott-2/lib/x86, /data/app/com.mls.Search.Abbott-2/base.apk!/lib/x86, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at android.app.ActivityThread.installProvider(ActivityThread.java:5141) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[dex file "/data/data/com.mls.Search.Abbott/files/instant-run/dex/slice-slice_3-classes.dex"],nativeLibraryDirectories=[/data/app/com.mls.Search.Abbott-2/lib/x86, /data/app/com.mls.Search.Abbott-2/base.apk!/lib/x86, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90) at com.android.tools.fd.runtime.IncrementalClassLoader.findClass(IncrementalClassLoader.java:62) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 12 more Suppressed: java.lang.ClassNotFoundException: android.support.v4.content.FileProvider at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 13 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available 

Manifest File Provider:

 <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths" /> </provider> 
+5
android android-emulator android-studio android-fileprovider
source share
3 answers

If you use Android 5.0 or lower in your emulator (level 21 api) then add the multidex support library to your project:

  • If your minSdkVersion is set to 21 or higher, all you have to do is set the multiDexEnabled parameter to true in the build.gradle file at the module level, as shown below:

     android { defaultConfig { ... minSdkVersion 21 targetSdkVersion 26 multiDexEnabled true } ... } 
    1. If minSdkVersion is set to 20 or lower, you should use the multidex support library as follows:

Modify the build.gradle file at the module level to include multidex, and add the multidex library as a dependency, as shown below:

 android { defaultConfig { ... minSdkVersion 15 targetSdkVersion 26 multiDexEnabled true } ... } 

dependencies {compile 'com.android.support:multidex:1.0.1'}

Take a look at https://developer.android.com/studio/build/multidex.html#mdex-gradle

0
source share

If you use androidx libraries, in AndroidManifest.xml change this:

 android:name="android.support.v4.content.FileProvider" 

on this:

 android:name="androidx.core.content.FileProvider" 
0
source share

Try using the Disable Instant Run option in Android Studio.

Choose File → Settings → Build, Execution, Deployment → Instant Launch → Cancel all flags.

I do not get this error when I create and run the application through the Android studio.

But this error occurs when you manually install apk on your device.

enter image description here

-one
source share

All Articles