My app is crashing on pre-21 with java.lang.NoClassDefFoundError app.module.SomeClass
error.
I already have Multidex enabled:
build.gradle:
android {
defaultConfig {
...
multiDexEnabled true
}
}
dependencies {
...
implementation "androidx.multidex:multidex:2.0.1"
}
My Application class:
class App : DaggerApplication() {
...
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(this)
}
After reading about Declaring classes required in the primary DEX file I created multidex-config.pro
file to include app.module.**
in primary DEX file:
-keep class app.module.** { *; }
And registered it in build.gradle:
android {
buildTypes {
debug {
...
multiDexKeepProguard file('multidex-config.pro')
}
}
I confirmed it by checking build/intermediates/legacy_multidex_main_dex_list/debug/mainDexList.txt
and analyzing the debug apk (checking whether classes.dex
includes app.module.SomeClass
).
But I'm still getting java.lang.NoClassDefFoundError app.module.SomeClass
error.
I also tried cleaning caches, running on different machines (cli build only without Android Studio), disabling instant run, specifying javaMaxHeapSize
, just extending MultiDexApplication
and etc.
What can I try next?