Search code examples
androidandroid-gradle-pluginproguarddex

Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded


I am trying to generate a signed apk of my app and I receive the following error

Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded

Error:Execution failed for task ':app:transformClassesWithDexForRelease'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --force-jumbo --num-threads=4 --multi-dex --main-dex-list C:\Users\user\Desktop\Mystuff\GetALifFitness\WonderStree-Production\app\build\intermediates\multi-dex\release\maindexlist.txt --output C:\Users\user\Desktop\Mystuff\GetALifFitness\WonderStree-Production\app\build\intermediates\transforms\dex\release\folders\1000\1f\main C:\Users\user\Desktop\Mystuff\GetALifFitness\WonderStree-Production\app\build\intermediates\transforms\proguard\release\jars\3\1f\main.jar}

I have tried some of the solutions to this from this link Too many classes in --main-dex-list, main dex capacity exceeded But it does not work for me. Can you guys please suggest me what could be wrong or provide me with the solution? Thank you.

What I have already tried - This is how my proguard file looks like:

-keepclassmembers class toan.android.floatingactionmenu.FloatingActionsMenu$RotatingDrawable { void set*(***);   *** get*(); }

-ignorewarnings

-keep class * {    public private *; }

-dontwarn okio.**

-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

-dontwarn com.mixpanel.**

And build.gradle file I added:

dexOptions {
        javaMaxHeapSize "4g"
        keepRuntimeAnnotatedClasses false
}

Also, I removed the unwanted libraries. Yet this problem is not solved.


Solution

  • I solved the issue by removing this particular line from build.gradle file

    multiDexKeepProguard file('proguard-rules.pro')

    This is how my build.gradle file looks now

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            ext.enableCrashlytics = true
        }
    }