Android 打包签名DexIndexOverflowException错误解决

来源:互联网 发布:中国历史故事软件 编辑:程序博客网 时间:2024/06/16 18:19

http://blog.csdn.net/zhoumushui/article/details/52795221


应用要使用谷歌地图服务,集成了Google Play Services,使用Android Studio打包release版本编译的时候出现如下错误:

Error:Execution failed for task ':watchclient:transformClassesWithDexForRelease'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

DexIndexOverflowException,从名字上看是Dex的Index溢出了。在stackoverflow上看到64K的说法:

当出现这个错误时说明你本身自己的工程代码中含有的太多的方法,或者你的工程lib文件夹下引用的第三方插件jar包有太多的方法,这两者的方法加起来已经超过了65536这个数目。而谷歌规定单个dex文件中的方法不能超过65536的限制

解决方案如下,修改module的build.gradle:

dependencies {    ...    compile 'com.android.support:multidex:'    ...    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5
android {    ...    defaultConfig {        ...        multiDexEnabled true        ...    }    ...}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这样就解决了DexIndexOverflowException这个异常: 
这里写图片描述


0 0