本文介绍了有没有一种方法,而使用MultiDex功能在Android的工作室,以限制主DEX文件的方法量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我启用了 MultiDex功能在Android的工作室像文件说,这自动spilted成两个或更多地塞米松的文件。我不能配置它。并且似乎在主DEX文件,方法的量是非常接近的限制(65536)。

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).

现在的问题是如何配置它,使主DEX文件的方法量减少到一定数量,比如60K。我要上传的APK亚马逊AppStore的,和亚马逊的人都会添加一些方法到主DEX文件并使其超过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.

推荐答案

DX工具有以下选项:

dx tool has the following options:

  • - 最小-主DEX - 将会把只由主DEX-列表中选择进入主DEX类
  • - 设置-MAX-IDX-号 - 无证选项,确定每个单独的DEX文件的方法,最大数量
  • --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.

您必须通过指定这两个选项,自定义的 build.gradle 的脚本。在例(来源):

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)
}

请注意,这不会帮助,如果你的主要DEX过大。这里是规则支配哪些类应该放在主DEX。我的博客上讲述他们在这里

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.

这篇关于有没有一种方法,而使用MultiDex功能在Android的工作室,以限制主DEX文件的方法量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!