奇怪:意外的顶级异常:任务应用的执行失败:dexDebug

时间:2015-02-02 20:28:38

标签: android

我没有实现新的库,但编码时出现了这个问题:

错误:任务':app:dexDebug'执行失败。

  

com.android.ide.common.internal.LoggedErrorException:无法运行命令:       C:\ android-sdk \ build-tools \ 21.1.1 \ dx.bat --dex --no-optimize --output F:\ Android_Donbas \ ReDonbasIDEANew \ app \ build \ intermediates \ dex \ debug --input-list = F:\ Android_Donbas \ ReDonbasIDEANew \应用\建立\中间体\ TMP \ DEX \调试\ inputList.txt   错误代码:       2   输出:       意外的顶级例外情况:       com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中:65536           在com.android.dx.merge.DexMerger $ 6.updateIndex(DexMerger.java:502)           在com.android.dx.merge.DexMerger $ IdMerger.mergeSorted(DexMerger.java:277)           在com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)           在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)           在com.android.dx.merge.DexMerger.merge(DexMerger.java:189)           在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)           在com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)           在com.android.dx.command.dexer.Main.run(Main.java:245)           在com.android.dx.command.dexer.Main.main(Main.java:214)           在com.android.dx.command.Main.main(Main.java:106)

我的build.gradle:

 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.google.code.gson:gson:2.2.2'
    compile 'com.google.guava:guava:18.0'
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile files('libs/android-async-http-1.4.6.jar')
    compile files('libs/AndroidSwipeLayout-v1.1.6.jar')
    compile files('libs/apache-mime4j-0.5.jar')
    compile files('libs/crashlytics.jar')
    compile files('libs/httpclient-4.2.1.jar')
    compile files('libs/httpcore-4.2.1.jar')
    compile files('libs/httpmime-4.2.1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/ormlite-android-4.48.jar')
    compile files('libs/ormlite-core-4.48.jar')
    compile files('libs/ormlite-jdbc-4.48.jar')
    compile files('libs/osmdroid-android-4.2.jar')
    compile files('libs/slf4j-android-1.6.1-RC1.jar')
    compile files('libs/universal-image-loader-1.9.3.jar')
}



packagingOptions {
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.t'
    }

4 个答案:

答案 0 :(得分:9)

您可能已达到65k方法限制。要更精确地使用Google Play服务,请按this guide,您只能使用所需的部分。这可能会解决您的问题。

答案 1 :(得分:4)

您可以通过添加“multiDexEnabled true”在build.gradle中启用multdex来修复限制问题。有关详细信息,请参阅http://android-developers.blogspot.com.es/2014/12/google-play-services-and-dex-method.html

摘自Why did this happen? How do i fix this? Android: UNEXPECTED TOP-LEVEL EXCEPTION:

答案 2 :(得分:2)

在build.gradle的defaultConfig中添加multiDexEnabled true解决了我的问题

defaultConfig {
        applicationId "com.example.project"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0.0"
        multiDexEnabled true
    }

答案 3 :(得分:0)

我在build gradle中添加了这些问题解决了我的问题:

    defaultConfig {
      multiDexEnabled true


    dependencies {
      compile 'com.android.support:multidex:1.0.0'

另一种解决方案可以删除不必要的库