[英]Android Studio Multiple Dex Error
I looked at the related topics but i couldn't find any solution. 我查看了相关主题,但找不到任何解决方案。 First time i run the project, the emulator opened, but then it started to give an error. 第一次运行项目时,模拟器打开了,但随后开始出现错误。 How i can solve this problem? 我该如何解决这个问题? Regards... 问候...
My error: 我的错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/http/entity/mime/FormBodyPart;
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: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 ':userAndroid:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 19.946 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
My build.gradle: 我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '23.0.0 rc2'
defaultConfig {
applicationId "com.user.android"
minSdkVersion 14
targetSdkVersion 19
// multiDexEnabled = true
}
/*dexOptions {
preDexLibraries = false
incremental true
javaMaxHeapSize "4g"
}*/
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':slidingMenuLibrary')
compile project(':pullToRefreshLibrary')
compile project(':placeActivity')
compile project(':jMC')
compile project(':salesforceSDK')
compile project(':library')
compile files('libs/android-integration-2.3-SNAPSHOT.jar')
compile files('libs/aws-android-sdk-1.4.4-core.jar')
compile files('libs/aws-android-sdk-1.4.4-s3.jar')
compile files('libs/com.radaee.pdfex_view.jar')
compile files('libs/commons-lang3-3.1.jar')
compile files('libs/core-2.3-SNAPSHOT.jar')
compile files('libs/ksoap2-android-assembly-3.2.0-jar-with-dependencies.jar')
compile files('libs/libGoogleAnalyticsServices-v3.01.jar')
compile files('libs/universal-image-loader-1.8.5-with-sources.jar')
compile files('libs/urbanairship-lib-3.0.0.jar')
compile 'com.google.api.client:google-api-client-repackaged-com-google-common-base:1.2.3-alpha'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:support-v4:22.2.0'
}
Edit:I have compile 'com.android.support:support-v4:22.2.0' in different files. 编辑:我在不同文件中编译了com.android.support:support-v4:22.2.0 。
build.gradle for my JMC library: 我的JMC库的build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 17
buildToolsVersion '23.0.0 rc2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('../libMaster/acra-4.2.3.jar')
compile files('../libMaster/apache-mime4j-0.5.jar')
compile files('../libMaster/commons-io-2.4.jar')
compile files('../libMaster/httpclient-4.0.jar')
compile files('../libMaster/httpcore-4.0-beta3.jar')
compile 'com.google.guava:guava:18.0'
compile files('../libMaster/httpmime-4.0-beta2.jar')
compile 'com.android.support:support-v4:22.2.0'
} }
Android newer build tools have support for mutidex. Android较新的构建工具支持mutidex。 you can enable multidex support by editing your build.gradle file like below 您可以通过编辑build.gradle文件来启用multidex支持,如下所示
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
Also you have @override this method in your Application class 您也可以在Application类中使用@override此方法
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Discover this: https://github.com/mihaip/dex-method-counts Tools show you libs that have many methods. 发现这一点: https : //github.com/mihaip/dex-method-counts工具向您展示具有许多方法的库。 Your dependency in graddle so huge, are you really using all of it? 您对gradle的依赖性如此之大,您是否真的在使用所有这些? If no try to delete unused 如果没有尝试删除未使用的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.