安卓"UNEXPECTED TOP-LEVEL EXCEPTION"



由于某种原因,我的项目停止了工作。当我尝试运行它时,我得到以下错误:

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:UsersLENOVOAppDataLocalAndroidsdkbuild-tools21.1.2dx.bat --dex --output C:UsersLENOVOProjectsStock.comLiveV2b18-v12-1903appbuildintermediatesdexdebug --input-list=C:UsersLENOVOProjectsappyappbuildintermediatestmpdexdebuginputList.txt
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lbolts/AggregateException;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        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)

昨天的项目很好,我没有改变任何感觉。我的等级文件:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "com.stock.app"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 4
        versionName "1.0.4"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'

    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'com.facebook.android:facebook-android-sdk:3.21.1'
    compile 'com.google.android.gms:play-services:6.1.+'
    compile files('libs/gson-1.7.jar')

    compile ('oauth.signpost:signpost-commonshttp4:1.2.1.2') {
        exclude module: 'commons-logging'
        exclude module: 'httpcore'
        exclude module: 'httpclient'
    }
    compile ('oauth.signpost:signpost-core:1.2.1.2') {
        exclude module: 'commons-codec'
    }

    compile 'com.parse.bolts:bolts-android:1.+'
    compile fileTree(dir: 'libs', include: 'Parse-*.jar')

    compile 'com.mcxiaoke.volley:library:1.0.+'
}

我能做什么?在搜索解决方案后,找到了一个说要取代这个的解决方案:

classpath 'com.android.tools.build:gradle:1.0.1'

这个:

classpath 'com.android.tools.build:gradle:1.1.2'

但这并没有奏效。

更新:我尝试删除解析螺栓,但出现了相同的错误。我当前的等级:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'

    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'com.facebook.android:facebook-android-sdk:3.21.1'
    compile 'com.google.android.gms:play-services:6.1.+'
    compile files('libs/gson-1.7.jar')

    compile ('oauth.signpost:signpost-commonshttp4:1.2.1.2') {
        exclude module: 'commons-logging'
        exclude module: 'httpcore'
        exclude module: 'httpclient'
    }
    compile ('oauth.signpost:signpost-core:1.2.1.2') {
        exclude module: 'commons-codec'
    }

    compile fileTree(dir: 'libs', include: 'Parse-*.jar')

    compile 'com.mcxiaoke.volley:library:1.0.+'
}

编辑:事实证明,问题是我有3个螺栓:一个来自Facebook,一个来自Parse.com,还有一个来自app-compact。我不得不去掉其中的两个。

到目前为止,我仍然不明白这个项目是如何运作的——因为我从第一天起就使用所有这些库。

Facebook SDK和appcompact库附带的lbolts android库可能会导致版本不匹配,从而导致DexException。

检查这个问题。

查看项目中包含哪些专用库,尤其是在存在多个lbolt实例的情况下。

问题的出现是因为您试图对同一工件进行两次打包。正如你可以从"facebookandroidsdk"POM文件中看到的,这个库已经打包了"boltsandroid"。因此,只需从构建文件中删除此依赖项,它就会起作用:

compile 'com.parse.bolts:bolts-android:1.+'

相关内容

最新更新