Android support Multidex still generates the 'over than 64K methods in main-dex file' error

Joshua Sardinha :

I'm an Android developer still supporting the minSdk 19 and faced an issue about the Maindex not fitting the requested classes in the main-dex file. Even after following the recommended steps at the 'Enable multidex' developers page, the error persists. What can I do to support more methods in the main-dex files, or better divide them between the files?

I have followed the steps suggested in the https://developer.android.com/studio/build/multidex page. In the Gradle file, I've implemented the 'com.android.support:multidex:1.0.3' dependency. My application extends from MultiDexApplication.

The main issue might be that the migration to the AndroidX was already made, so the application imports androidx.multidex.MultiDexApplication library instead of importing the support one, which was implemented in the dependencies.

Inside the build.gradle(Module:App) file (only the important parts are highlighted)

...
dexOptions {
   jumboMode true
}
...
defaultConfig {
    minSdkVersion 19
    targetSdkVersion 28
    ...    
    multiDexEnabled true
    multiDexKeepProguard file('multidex-config.txt')
}
...
dependencies {
    ...
    implementation "com.android.support:multidex:1.0.3"
    ...
}

In the application file:

import androidx.multidex.MultiDexApplication;
...
public class MainApplication extends MultiDexApplication...

The expected was, with the attempts made, that the methods would fit in the dex files. However, the error persists when trying to build the APK:

Error: null, Cannot fit requested classes in the main-dex file (# methods: 66064 > 65536)
Tito Rezende :

According to documentation you must have in your multidex-config the classes you want to keep.

Analyze your APK and check for the classes and methods there are included on the main dex file and check the packages that are contributing the reach the 64K limit.

Make sure you are not keeping your entire project on the multidex-config file.

The example given in the documentation can be misleading if you use a broad package filter:

-keep class com.example.** { *; }

Try to keep only necessary packages:

-keep class com.example.YOUR-PACKAGE** { *; }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=162942&siteId=1