0

One of my test phone does not able to install app with ADB when the application class is extending MultiDex application.

I attempted implement this on build.gradle with my app application class extending MultiDexApplication but cannot compile.

buildTypes {
 release {
    multiDexEnabled false
 }
 debug {
    multiDexEnabled true
 }
}

References: 1. https://developer.android.com/studio/build/multidex.html 2. Can I enable multidex in Android debug build only? 3. Conditionally inherit from class

Lee Chun Hoe
  • 728
  • 11
  • 19

2 Answers2

0

Keep your Application class extend MultidexApplication, but add this line into your attachBaseContext

if (BuildConfig.DEBUG) {
    MultiDex.install(this);
}
phatnhse
  • 3,870
  • 2
  • 20
  • 29
0

Maybe I can suggest a different approach. I assume you are using proguard on your release build and this is why you don't need to use multidex for release

If you set minifyEnabled true and useProguard false on debug, this will strip out all the dead code in your debug build but wont use any of the proguard optimizations like obfuscation.

You will need to move your proguard rule settings into default config so minify knows which files to keep.

This method can help you avoid using multidex on your debug builds.

defaultConfig {
    ...
    proguardFile 'proguard-rules.pro'
    proguardFiles getDefaultProguardFile('proguard-android.txt')
}

debug {
    ...
    minifyEnabled true
    useProguard false
}

release {
    ...
    minifyEnabled true
}
Eoin
  • 4,050
  • 2
  • 33
  • 43