Android FileProvider class not found in build versions

I use FileProvider to get photos from the device. The implementation works fine in debug builds (minifyEnabled false), but when I create the release assembly (minifyEnabled true), I get an error message:

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.package.name-2/base.apk"], nativeLibraryDirectories=[/data/app/om.package.name-2/lib/arm, /vendor/lib, /system/lib]] 

So, I think this has to do with installing proguard

I have

 compile 'com.android.support:support-v13:23.1.1' 

which is a superset of v4 in the gradle file and

 minSdkVersion 21 targetSdkVersion 23 

and

 -keep class android.support.v4.app.** { *; } -keep class android.support.v4.content.** { *; } -keep interface android.support.v4.app.** { *; } -keep interface android.support.v4.content.** { *; } -keep class * extends android.content.ContentProvider 

in the file proguard-rules.pro

I tested with Android 5 and 6, and the same thing happens. Any suggestion would be helpful, thanks in advance.

+8
android proguard android-support-library
source share
4 answers

I used the androidx library and got the same error. So, in AndroidManifest.xml I changed this line:

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

on this:

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

The following worked for me:

In the build.gradle build file:

 defaultConfig { ... multiDexEnabled true ... 

}

Then:

 dependencies { ... compile 'com.android.support:multidex:1.0.2' ... 

}

Finally, make sure your application class has one of the following values:

but. If you do not extend your application class:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application android:name="android.support.multidex.MultiDexApplication" > ... </application> </manifest> 

C. If you extend your application class and can change the base class:

 public class MyApplication extends MultiDexApplication { ... } 

C. If you extend your application class and cannot change the base class:

  public class MyApplication extends SomeOtherApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 

For more information:

https://developer.android.com/studio/build/multidex.html#mdex-gradle

+16
source share

After a couple of hours of more searches, I finished updating gradle and google services

 dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath 'com.google.gms:google-services:1.5.0' } 

earlier version of ware

  classpath 'com.android.tools.build:gradle:1.3.0' classpath 'com.google.gms:google-services:1.5.0-beta2' 

I assume the google-services library should be something like

-one
source share
 java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" 

unrelated to programming if it worked previously with the proper configuration.

Check out this link if it helps someone in some way.

Could not find problem with file provider

-one
source share

All Articles