在我的项目中,当我想在我的应用程序中将 google play 依赖项添加到 ues google map 时出现问题。问题是当我想运行项目时出现这些错误:
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
这是我的依赖项:
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')
}
我还删除了所有库,因为尽管它们在 google play 8.1.0 上可能有问题,但没有任何改变。我还尝试从所有编译中排除 com.google.android.gms:play-services
但它也没有用。
最佳答案
首先,请注意您的依赖 block 。
您正在使用同一库的不同版本,可能是不必要的依赖项。
在任何情况下都使用相同的版本。
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.
}
如果问题依旧,说明你的方法太多了。 dex 只能有65536 个方法。
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
从 gradle 插件 0.14.0 和构建工具 21.1.0 开始,您可以使用 multidex support .
只需在 build.gradle
中添加这些行:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
同样在您的 Manifest
中,将 multidex 支持库中的 MultiDexApplication
类添加到应用程序元素
<?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>
如果您使用自己的 Application
类,请将父类从 Application
更改为 MultiDexApplication
。
关于android - 意外的顶级异常 : com. android.dex.DexIndexOverflowException 合并依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33590477/