当我尝试构建我的应用程序时,突然遇到了以下问题:
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
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:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
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_51\bin\java.exe'' finished with non-zero exit value 2'从读取其他线程来看,它与拥有超过65k个方法有关。然而,我的应用程序远没有那么多,它仍然是一个小应用程序。我不确定这是否包括gradle文件中包含的其他库。
这是我的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 14
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/jasypt-1.9.2.jar')
apply plugin: 'com.google.gms.google-services'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'me.dm7.barcodescanner:zbar:1.6.3'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.mobsandgeeks:android-saripaar:2.0.3'
compile 'com.github.satyan:sugar:1.3.1'
compile 'uk.co.ribot:easyadapter:1.5.0@aar'
compile 'com.android.support:design:23.1.0'
}我如何确定我是否达到了这个限制,如果是的话,有没有办法来查看哪个包含的库如此之大?另外,启用multiDexEnabled true的缺点是什么
老实说,我不想启用multiDex,这个应用程序不应该这么大。我宁愿解决问题的根源。
发布于 2015-10-26 18:15:01
这个错误的发生是因为你有超过65k的方法,这超出了dex的容量。
您可以使用这个库来检查您的方法是否超过65k,或者不是https://github.com/KeepSafe/dexcount-gradle-plugin
如果你有超过65,000,你需要他们,你应该到你的gradle
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true // Add this
}请查看此处的文档http://developer.android.com/tools/building/multidex.html
尽管您并不需要所有的播放服务方法都使用您真正需要的内容,但您应该查看此文档以使用您仅需要的内容。https://developers.google.com/android/guides/setup
此外,正如@IntelliJAmiya所说的那样,删除这个
apply plugin: 'com.google.gms.google-services'因为是重复的,所以您已经在使用
'com.google.android.gms:play-services:8.1.0'发布于 2015-10-26 18:30:19
将此添加到您的build grandle中
android {
.....
multiDexEnabled true
}并将multidex添加到您的依赖项中,然后尝试重新构建
dependencies {
compile 'com.android.support:multidex:1.0.0'
}编辑:在您的清单中添加多索引应用程序:
<?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>EDIT 2 :或者,如果您有一个扩展了应用程序的类,则在您的类的attachBaseContext()中添加MultiDex.install(this) (如果不存在,则覆盖它)
发布于 2015-10-26 18:16:52
先把这个去掉
apply plugin: 'com.google.gms.google-services'实际上你已经打电话给compile 'com.google.android.gms:play-services:8.1.0' .So了,不需要再打电话了。
然后清理和重建
最后
dependencies {
compile files('libs/jasypt-1.9.2.jar')
compile 'com.android.support:support-v4:23.1.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'me.dm7.barcodescanner:zbar:1.6.3'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.mobsandgeeks:android-saripaar:2.0.3'
compile 'com.github.satyan:sugar:1.3.1'
compile 'uk.co.ribot:easyadapter:1.5.0@aar'
compile 'com.android.support:design:23.1.0'
}编辑1个
调用multiDexEnabled true
看起来
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true
}并添加以下内容
compile 'com.android.support:multidex:1.0.1'https://stackoverflow.com/questions/33343111
复制相似问题