Android Studio多个dex文件定义Lcom / abc / xyz / BuildConfig

时间:2015-02-10 09:50:48

标签: android android-studio android-gradle build.gradle

我是Android Studio的新手,每次尝试运行我的应用时都面临异常

Error:Execution failed for task ':abc:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/nik/Installs/adt-bundle-linux-x86_64-20140702/sdk/build-tools/21.1.2/dx --dex --no-optimize --output /home/nik/workspace/androidstudio/abc/build/intermediates/dex/debug --input-list=/home/nik/workspace/androidstudio/abc/build/intermediates/tmp/dex/debug/inputList.txt


Error Code:
2


Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/abc/xyz/BuildConfig;
    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)

尝试很多解决方案,比如删除BuildConfig文件等,但没有运气。经过大量的谷歌搜索我才明白,问题与多个依赖文件有关,但无法解决。

也尝试命令 gradle -q依赖项 但失败并出现此错误

FAILURE:由于内部错误导致构建中止。

  • 出了什么问题: 由于意外的内部错误导致构建中止。请在以下网址提交问题:http://forums.gradle.org

另外我想提一下,我在Android Studio中运行Build-> Rebuild Project时尝​​试从eclipse及其构建中成功迁移我的项目

boxAndroidLibraryV2

dependencies {


compile project(':boxJavaLibraryV2')
compile 'com.android.support:support-v4:19.1.0'
//compile 'com.android.support:support-v4:18.0.0'
compile files('libs/commons-codec.jar')
compile files('libs/commons-io-2.3.jar')
compile files('libs/commons-lang-2.6.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/httpclient-cache-4.2.5.jar')
compile files('libs/httpmime-4.2.5.jar')
compile files('libs/jackson-annotations-2.0.0.jar')
compile files('libs/jackson-core-2-1.0.0.jar')
compile files('libs/jackson-databind-2-1.0.0.jar')
}

boxJavaLibraryV2

dependencies {


compile files('libs/cglib-nodep-2.2.2.jar')
compile files('libs/commons-codec-1.6.jar')
compile files('libs/commons-io-2.3.jar')
compile files('libs/commons-lang-2.6.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/easymock-3.1.jar')
compile files('libs/httpclient-4.2.5.jar')
compile files('libs/httpclient-cache-4.2.5.jar')
compile files('libs/httpcore-4.2.4.jar')
compile files('libs/httpmime-4.2.5.jar')
compile files('libs/jackson-annotations-2.0.0.jar')
compile files('libs/jackson-core-2-1.0.0.jar')
compile files('libs/jackson-databind-2-1.0.0.jar')
compile files('libs/junit-4.8.2.jar')
compile files('libs/powermock-easymock-1.4.12-full.jar')
compile files('libs/robolectric-1.2-20121030.213744-165-jar-with-dependencies.jar')
}

MYLIB

dependencies {


compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.guava:guava:17.0'
compile files('libs/commons-codec.jar')
compile files('libs/sqlcipher.jar')
}

对myApp

dependencies {


compile project(':boxAndroidLibraryV2')
compile project(':liveSdk')
compile project(':mylib')
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.http-client:google-http-client-gson:1.19.0'
compile 'com.google.code.gson:gson:2.1'
compile 'com.google.android.gms:play-services:+'
compile files('libs/HockeySDK-3.0.2.jar')
compile files('libs/dropbox-android-sdk-1.5.4.jar')
compile files('libs/google-api-client-1.14.1-beta.jar')
compile files('libs/google-api-client-android-1.14.1-beta.jar')
compile files('libs/google-api-services-drive-v2-rev70-1.14.1-beta.jar')
compile files('libs/google-http-client-1.14.1-beta.jar')
compile files('libs/google-http-client-android-1.14.1-beta.jar')
compile files('libs/google-oauth-client-1.14.1-beta.jar')
compile files('libs/icu4j-4.8.1.jar')
compile files('libs/in-app-purchasing-2.0.59.jar')
compile files('libs/json_simple-1.1.jar')

}

我知道某些依赖项在盒式库中是多个,如

编译文件(' libs / commons-io-2.3.jar') 编译文件(' libs / commons-lang-2.6.jar')

但如果我尝试删除这些而不是面对异常

Error:(6, 29) error: package org.apache.commons.io does not exist
Error:(80, 13) error: cannot find symbol variable IOUtils
Error:(6, 32) error: cannot find symbol class CharEncoding
Error:(57, 75) error: cannot find symbol variable CharEncoding
Error:(58, 79) error: cannot find symbol variable CharEncoding etc...

感谢您的任何建议

1 个答案:

答案 0 :(得分:4)

经过多次试验

dexOptions {
    preDexLibraries = false
    javaMaxHeapSize "4g"
}

这对我有用..