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.
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
After a couple of hours of more googling around I've ended up updating gradle and google services to
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0'
}
previously the version ware
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
I guess there needs to be something with the google-services library