8

We are having problems in building our multidex App. We keep receiving different java.lang.NoClassDefFoundError erros during the application boot.

We noticed that they are very likely related to the multidex issues. As the required classes for booting the App must be present in the primary DEX file and they are not being included in the classes.dex. We performed the steps described in https://developer.android.com/studio/build/multidex.html#keep but the classes we specify in the multidex-config.txt, or even in the multidex-config.pro are not being placed in the primary dex file (classes.dex).

Do you guys have experience using the multiDexKeepFile or the multiDexKeepProguard? Does it really work? Is there any trick to make it work and place the files in the classes.dex?

3 Answers3

3

Try updating your gradle plugin. I've seen that in 2.2.0 the configuration is ignored entirely. When I updated to 2.3.3 it started respecting the rules I set.

Example:

classpath com.android.tools.build:gradle:2.3.3

And in my default config I have this set:

    multiDexEnabled true
    multiDexKeepProguard file('proguard.multidex.config')

Also you may have to do a clean build before the changes are reflected.

Travis Castillo
  • 1,807
  • 1
  • 20
  • 23
  • 3
    I'm using the (current) latest gradle plugin version - `classpath 'com.android.tools.build:gradle:3.5.3'`, but am still having the OP's problem. Also, by inspecting my apk ( https://developer.android.com/studio/build/apk-analyzer ), I see the classes I have specified via `multiDexKeepFeel` are present in **classes2.dex** rather than in the *primary* dex file, **classes.dex**. – ban-geoengineering Dec 19 '19 at 17:15
1

I have the same problem.And i still don't know why. But i found another solution,and it works. In your app module's build.gradle add dexOptions:

android {
    dexOptions {
        additionalParameters = ['--multi-dex',
                                '--set-max-idx-number=60000',
                                '--main-dex-list='+projectDir+'/your_multidexconfig.txt',
                                '--minimal-main-dex'
        ]
    }
}
you
  • 51
  • 4
1

You should check your minSdkVersion, if your minSdkVersion is >= 21, multiDexKeepProguard is not supported. Because the build tools has do the dex split by default.

More details:

https://developer.android.com/studio/build/multidex

Cobain
  • 186
  • 1
  • 8