AndroidStudio:The number of method references in a .dex file cannot exceed 64K错误

在AndroidStudio中出现下面的错误提示:

Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

Error:Execution failed for task ':xxx:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

根据提示信息可以看到,出现这个问题,是因为App里面方法数超过64K。实际上大部分情况下都是因为包的重复导入造成的。

怎么解决这个问题呢?

一. 删掉重复的依赖包。另外,在build.gradle中,把包版本设成一致。

二. 修改build.gradle文件。
1.在dependencies中,添加

compile 'com.android.support:multidex:1.0.1'

2.在 defaultConfig 中添加

multiDexEnabled true

三. 查看AndroidManifest.xml文件中,application节点下,android:name=”“所对应的Application。在Application里面重写attachBaseContext方法。如下图所示:

application

attachBaseContext

这样修改完就不会再出现上面的错误提示了。

posted on 2018-05-30 18:48  lishbo  阅读(165)  评论(0编辑  收藏  举报