意外的顶级异常:com.android.dex.DexIndexOverflowException 合并依赖项
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException merging dependencies
在我的项目中,当我想将 google play 依赖项添加到我的应用程序中的 ues google 地图时出现问题。问题是当我想要 运行 项目时,我给出了这些错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger.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 播放 8.1.0 时遇到问题但没有任何改变。我也试图从所有编译中排除 com.google.android.gms:play-services
但它也没有用。
检查你的代码..
依赖关系 {
编译文件树(目录:'libs',包括:['*.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')
}
非零退出值 2 当您在代码中实现任何库两次时会发生错误.. 编译 'com.android.support:appcompat-v7:22.0.0' 和 编译 'com.android.support:appcompat-v7:22.2.0'
请删除其中一个。
还要检查 'libs' 文件夹中的其他库。这对我有用。希望这对你有帮助。
首先,注意你的依赖块。
您正在使用同一库的不同版本,可能是不必要的依赖项。
在任何情况下都使用相同的版本。
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 和 Build Tools 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
class 添加到应用程序元素
<?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
class,请将父 class 从 Application
更改为 MultiDexApplication
。
在我的项目中,当我想将 google play 依赖项添加到我的应用程序中的 ues google 地图时出现问题。问题是当我想要 运行 项目时,我给出了这些错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger.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 播放 8.1.0 时遇到问题但没有任何改变。我也试图从所有编译中排除 com.google.android.gms:play-services
但它也没有用。
检查你的代码.. 依赖关系 {
编译文件树(目录:'libs',包括:['*.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')
}
非零退出值 2 当您在代码中实现任何库两次时会发生错误.. 编译 'com.android.support:appcompat-v7:22.0.0' 和 编译 'com.android.support:appcompat-v7:22.2.0' 请删除其中一个。
还要检查 'libs' 文件夹中的其他库。这对我有用。希望这对你有帮助。
首先,注意你的依赖块。
您正在使用同一库的不同版本,可能是不必要的依赖项。
在任何情况下都使用相同的版本。
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 和 Build Tools 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
class 添加到应用程序元素
<?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
class,请将父 class 从 Application
更改为 MultiDexApplication
。