Is there a way to limit method amount in main dex file while using MultiDex feature in Android Studio

北慕城南 提交于 2019-11-27 03:31:36

问题


When I enabled MultiDex feature in Android Studio like the document says, it automatically spilted into two or more dex files. I cannot config it. And it seems that in the main dex file, the amount of methods is very close to the limitation(65536).

The question is how to config it, make the amount of methods in the main dex file reduce to a certain number, say 60k. I have to upload the apk to amazon appstore, and the people of amazon will add a few methods into the main dex file and make it over the 65536 limit.


回答1:


dx tool has the following options:

  • --minimal-main-dex - will put only classes that selected by main-dex-list into the main dex.
  • --set-max-idx-number - undocumented option that determines maximum number of methods per single dex file.

You have to customize your build.gradle script by specifying those two options. In 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)
}

Note that this won't help if your main dex is too large. There're rules that govern which classes should be placed in main dex. I blogged about them here.

Edit (1-9-2016):
Version 1.5 of Android plugin doesn't allow to add additional parameters to dx, but it seems that it will be fixed in one of the upcoming versions.



来源:https://stackoverflow.com/questions/27631500/is-there-a-way-to-limit-method-amount-in-main-dex-file-while-using-multidex-feat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!