MultiDex: Main Dex Capacity Exceeded with MultiDex

2019-08-19 01:29发布

问题:

I'm using a package I've included into my project that requires MultiDex, I've got 156561 references so I'll need multiple .dex files.

However it fails, citing that the main dex file is too large

Some suggested using keepRuntimeAnnotatedClasses false, but I'm using Xamarin and its not clear on how to accomplish this without Gradle.

Others suggest setting the minimum API > 21, which is already true for my project.

I've also manually upgraded Proguard, as MultiDex uses it and got the newest 1.8 JDK

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:548)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:368)
at com.android.dx.command.dexer.Main.runDx(Main.java:289)
at com.android.dx.command.dexer.Main.main(Main.java:247)
at com.android.dx.command.Main.main(Main.java:94)

I would think that MultiDex would be the solution to 'Too many classes'. However it seems like whatever logic is deciding to fill the main dex file is over filling it

回答1:

Assuming you are using one of the latest versions of Xamarin.Android, you can try using the "new" Google D8 dex tool vs. using Proguard.

<PropertyGroup>
   <AndroidDexTool>d8</AndroidDexTool>
   <AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>
  • Android’s D8 dexer and R8 shrinker

Detailed info on the various D8/R8 project configurations can be found in the Xamarin.Android repo here:

  • This is the D8 and R8 integration specification for Xamarin.Android.