Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android FileProvider class not found in release builds

I'm using a FileProvider to get photos from the device. The implementation works just fine in debug builds (minifyEnabled false) but when I'm building the release build (minifyEnabled true) I get an error:

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 guess this has someting to do with the proguard setup

I have

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

which is a superset of v4 in my 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 my proguard-rules.pro file

I have tested with both Android 5 and 6 and same thing happens. Any suggestion would be usefull, thanks in advance.

like image 599
DraganescuValentin Avatar asked Jan 13 '16 11:01

DraganescuValentin


2 Answers

The following worked for me:

In your module build.gradle file:

defaultConfig {
...
multiDexEnabled true
...

}

Then:

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

}

And finally, ensure that your application class has one of the following:

A. 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>

B. If you do extend your Application class and but can change the base class:

public class MyApplication extends MultiDexApplication { ... }

C. If you do 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 info:

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

like image 193
Munier Parker Avatar answered Nov 20 '22 19:11

Munier Parker


I was using androidx library and getting the same error. So, in AndroidManifest.xml, I changed this line:

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

to this:

android:name="androidx.core.content.FileProvider"
like image 41
Darush Avatar answered Nov 20 '22 19:11

Darush