每个dex文件的最大引用方法数量

时间:2018-09-20 02:01:45

标签: android android-gradle multidex android-multidex

我的应用程序包含了超过64k的引用方法,因此我正在使用multidex创建dex文件:

android {
  defaultConfig {
      ...
      multiDexEnabled true
  }

  dexOptions {
    preDexLibraries false
  }
}

dependencies {
  compile 'com.android.support:multidex:1.0.3'
}

我正确配置了它,并创建了dex文件,但是我想知道是否有一种方法可以限制每个dex文件中引用方法的最大数量?我将Android 19设置为最低版本。

我的主要dex文件只有两种方法,最多只能使用65,536种方法,因此我希望将此数字降低到约60k种方法。目前无法使用ProGuard。

1 个答案:

答案 0 :(得分:0)

如果您使用任何Google Play服务,请仅包含所需的API,而不要包括完整的Google Play服务。例如,如果您使用admob广告,请添加依赖项

compile 'com.google.android.gms:play-services:9.0.0'

而不包括完整的播放服务库,例如'compile com.google.android.gms:play:9.0.0'。这样可以减小您的dex大小。