[英]Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId 'net.example.net.app'
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/DEPENDENCIES'
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
compile('org.apache.httpcomponents:httpmime:4.3.4') {
exclude module: 'org.apache.httpcompoents:httpcore'
exclude module: 'org.apache.httpcompoents:httpclient'
}
compile 'org.codehaus.jackson:jackson-core-asl:1.8.3'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.8.3'
}
Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:com.android.dex.DexException: Multiple dex files define Lorg/apache/http/conn/socket/LayeredConnectionSocketFactory;
错误:java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并 dex 错误:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并 dex错误:com.android.builder.dexing.DexArchiveMergerException:无法合并 dex 错误:com.android.dex.DexException:多个 dex 文件定义了 Lorg/apache/http/conn/socket/LayeredConnectionSocketFactory;
Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
错误:java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并 dex
You should upgrade your gms:play-services
& com.android.support
version.你应该升级你的
gms:play-services
& com.android.support
版本。
compile 'com.google.android.gms:play-services:11.6.0' //11.8.0
compile 'com.android.support:support-v4:26.0.2'
compile 'com.android.support:appcompat-v7:26.0.2'
After that, Clean-Rebuild-Run
.之后,
Clean-Rebuild-Run
。
FYI供参考
Enable multiDexEnabled
.启用
multiDexEnabled
。
defaultConfig {
multiDexEnabled true
}
You have enabled Multidex but missed to add dependency, add the following in dependencies你已经启用了Multidex但没有添加依赖,在依赖中添加以下内容
compile 'com.android.support:multidex:1.0.2'
then make sure your application class extends MultidexApplication.然后确保您的应用程序类扩展了 MultidexApplication。 Finally clean and rebuild project.
最后清理并重建项目。 Hope this will fix the issue
希望这能解决问题
For more check multidex doc in developer.android有关更多信息,请查看developer.android 中的 multidex 文档
It is because httpmime include httpclient in its dependencies.这是因为 httpmime 在其依赖项中包含 httpclient。 You need to exclude it.
你需要排除它。 Currently, you're using the wrong package name for excluding the httpclient:
目前,您使用错误的包名称来排除 httpclient:
compile('org.apache.httpcomponents:httpmime:4.3.4') {
exclude module: 'org.apache.httpcompoents:httpcore'
exclude module: 'org.apache.httpcompoents:httpclient'
}
it should be:它应该是:
compile('org.apache.httpcomponents:httpmime:4.3.4') {
exclude group: 'org.apache.httpcomponents', module: 'httpcore'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
if you got this error with phonegap/cordova so don't waste your time go back and regenerate new project on different path.如果您在使用 phonegap/cordova 时遇到此错误,请不要浪费时间返回并在不同的路径上重新生成新项目。 its work in my condition
它在我的条件下工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.