意外的顶级例外:com.android.dex.DexIndexOverflowException依赖合并
在我的项目有一个问题,当我想补充谷歌发挥依赖于正餐谷歌地图在我的应用程序。问题是,当我想运行的项目,我给这些错误:
in my project there is a problem when I wanna add google play dependency to ues google map in my app. the problem is when I wanna run project I give these errors:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:283)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_72\bin\java.exe'' finished with non-zero exit value 2
这是我的依赖关系:
and this is my dependencies:
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
versionCode 2
versionName "1.0.1"
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v13:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:support-v4:22.0.0'
compile 'com.google.android.gms:play-services:8.1.0'
compile ('org.bouncycastle:bcprov-jdk16:1.46')
compile ('com.nineoldandroids:library:2.4.0')
compile ('commons-lang:commons-lang:2.6')
compile ('com.google.zxing:core:3.2.0')
}
我还删除所有的图书馆,因为我虽然他们可能有问题,谷歌扮演8.1.0但是没有什么改变。我也试着排除 com.google.android.gms:发挥服务
所有编译,但它没有工作过。
I also remove all libraries cause I though they may had problem with google play 8.1.0 but nothings changed. also I tried to exclude com.google.android.gms:play-services
from all compile but it didn't work too.
首先,要注意您的相关模块。结果
您正在使用不同版本的同一个库的,可能是不必要的依赖。
First of all, pay attention to your dependencies block.
You are using different version of the same library and may be unnecessary dependencies.
使用相同版本在任何情况下。
dependencies{
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v13:22.0.0' ARE YOU SURE?
compile 'com.android.support:appcompat-v7:22.0.0' TWICE ? REMOVE IT
compile 'com.android.support:support-v4:22.0.0' APPCOMPAT contains it. REMOVE IT.
}
如果问题仍然存在,你有太多的方法。只能有 65536的方法DEX
If the issue persists, you have too many methods. There can only be 65536 methods for dex.
意外顶级例外:结果
com.android.dex.DexIndexOverflowException:方法ID不能在[0,0xFFFF的]:65536
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
由于插件的gradle和0.14.0构建工具21.1.0可以使用的 multidex支持 。
Since the gradle plugin 0.14.0 and the Build Tools 21.1.0 you can use the multidex support.
就在添加这些行的build.gradle
:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
另外,在你的清单
从multidex支持库添加 MultiDexApplication
类应用程序的元素
Also in your Manifest
add the MultiDexApplication
class from the multidex support library to the application element
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
如果您使用的是自己的应用
类,从应用
父类改为 MultiDexApplication
。
If you are using a own Application
class, change the parent class from Application
to MultiDexApplication
.