Android studio意外顶级异常

时间:2015-06-29 18:01:12

标签: java android android-studio

我遵循了这个问题的指南:Android Studio - UNEXPECTED TOP-LEVEL EXCEPTION:

但它仍然拒绝正确编译,我已经尝试寻找重复的条目但找不到它,错误如下

  

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Users\ShadowFox\Android-sdk\build-tools\21.1.1\dx.bat --dex --output C:\Work\SystemMonitor - version 4.0\app\build\intermediates\dex\debug --input-list=C:\Work\SystemMonitor - version 4.0\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support/v7/app/ActionBar$Callback;
        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:302)
        at com.android.dx.command.dexer.Main.run(Main.java:245)
        at com.android.dx.command.dexer.Main.main(Main.java:214)
        at com.android.dx.command.Main.main(Main.java:106)

然后我的模块:app build.gradle我有

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
       applicationId "edu.fiu.cis.visa.systemmonitor"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile files('libs/dropbox-android-sdk-1.6.3.jar')
    compile files('libs/httpmime-4.0.3.jar')
    compile files('libs/json_simple-1.1.jar')
    compile project(":libs:AndroidCommon")
}

我的图书馆的build.gradle如下

apply plugin: 'com.android.library'

dependencies {
    compile 'com.android.support:support-v4:21.0.3'
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
    }

 >   sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile files('libs/gson-2.2.2.jar')
        compile files('libs/jackson-all-1.9.11.jar')
        compile files('libs/RootTools-3.4.jar')
    }
} 

2 个答案:

答案 0 :(得分:0)

两次都会获取库com.android.support:appcompat-v7。删除第一个。

您获取了该库,然后您的图书馆build.gradle再次抓取它

答案 1 :(得分:0)

试试这个

app:build.gradle

中的

defaultConfig {
        applicationId "edu.fiu.cis.visa.systemmonitor"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        // Enabling multidex support.
        multiDexEnabled true
         }

并将其放入app:build.gradle文件

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