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

ぃ、小莉子 提交于 2019-11-28 10:14:35

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.

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