Reputation: 212
I'm trying to shrink my apk size by setting minifyEnabled and shrinkResources to true, but on start my application crashes with this error (short version):
java.lang.ClassNotFoundException: Didn't find class "...BaseApplication" on path: DexPathList...
I found many solutions for this error, but it seems, that everybody has crashes only on android 4.x.x. I'm testing on android 9 and still have this problem. Gradle looks like this:
defaultConfig {
minSdkVersion 17
targetSdkVersion 28
versionName "1.0"
multiDexEnabled true
}
And buildTypes:
buildTypes {
debug {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
And also I've added this one in my application class:
override fun attachBaseContext(base: Context?) {
MultiDex.install(this)
super.attachBaseContext(base)
}
I only have this error, if I'm trying to start the release build. When I start the debug variant with same settings, all works fine. And also if I'm adding "debuggable true" to my release variant it's ok. It's only occurs, when I'm trying to start my release variant like described above. Has anyone an Idea?
Upvotes: 2
Views: 3312
Reputation: 3353
when you do minifyEnabled true in release it means you need to mention what all files you dont want to obfuscate for eg. BaseApplication by mentioning it in proguard-rules.pro
Kindly write below line in proguard-rules.pro it will remove the above error with BaseApplication Class
-keep public class * extends android.app.Application
Kindly refer this link for further understanding about proguard.
If you are facing more problem kindly share content from proguard file.
Upvotes: 1