Is there a way to limit the number of methods in the main dex file when using the MultiDex function in Android Studio

When I turned on the MultiDex function in Android Studio, as the document says, it automatically spills into two or more dex files. I can’t configure it. And it seems that in the main dex file the number of methods is very close to the limit (65536).

The question is how to configure it, to make the number of methods in the main dex file reduced to a certain number, say 60k. I need to download apk in amazon appstore, and people from Amazon will add several methods to the main dex file and go to the limit of 65536.

+5
source share
1 answer
Tool

dx has the following options:

  • - minimum-main-dex - will only place the classes selected in the main-dex-list in the main dex file.
  • - set-max-idx-number - an undocumented option that determines the maximum number of methods for a single dex file.

You must customize your build.gradle script by specifying these two parameters. In the example ( source ):

tasks.withType(com.android.build.gradle.tasks.Dex) { dexTask -> def command = [] as List command << ' --minimal-main-dex' command << ' --set-max-idx-number=50000' dexTask.setAdditionalParameters(command) } 

Please note that this will not help if your main size is too large. There are rules that determine which classes should be placed in the main dex. I wrote about them here .

Edit (1-9-2016):
Version 1.5 of the Android plugin does not allow adding additional parameters to dx, but it seems that it will be fixed in one of future versions.

+10
source

Source: https://habr.com/ru/post/1209810/


All Articles