Ang*_*raj 67 android build-error android-studio-3.0
android studio在构建执行时出现构建错误,其中包含以下"错误:执行任务失败":app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex"
我的app:build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.pdroid.foodieschoice"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:appcompat-v7:26.0.1'
force 'com.android.support:support-compat:26.0.1'
force 'com.android.support:support-core-ui:26.0.1'
force 'com.android.support:support-annotations:26.0.1'
force 'com.android.support:recyclerview-v7:26.0.1'
}
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
任何解决方案
编辑:我已经通过firebase github网站完成了样本并解决了
Nia*_*shi 45
添加可能与您的兼容的外部库时会发生此错误compileSdkVersion.
添加时要小心external library.
我花了2天时间解决这个问题,最后按照这些步骤解决了问题.
确保您所有的支持库是一样compileSdkVersion的你build.gradle(Module:app)在我的情况下,它是26.
Sync 你的项目.
最后,转到Build | 点击Rebuild Project.
注意:重建项目首先清理然后构建项目.
Ish*_*ndo 31
尝试在gradle中添加它
android {
defaultConfig {
multiDexEnabled true
}
}
Run Code Online (Sandbox Code Playgroud)
小智 20
只需尝试"构建 - >清洁项目".这解决了我的问题.
Mod*_*era 16
请参阅此链接:由于有多种选项可根据minSdkVersion来关闭警告,因此将其设置为20以下:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
... }
dependencies { compile 'com.android.support:multidex:1.0.3' }
Run Code Online (Sandbox Code Playgroud)
如果您的build.gradle集合中的minSdkVersion大于20,请使用以下命令关闭警告:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
... }
Run Code Online (Sandbox Code Playgroud)
更新依赖关系,如下所示:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
同样,唯一的区别是依赖项中的关键字:
minSdkVersion低于20:使用编译
minSdkVersion 20以上:使用实现
对我来说,补充一下
multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)
和
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
Run Code Online (Sandbox Code Playgroud)
进入应用程序级别Build.gradle文件解决了这个问题
转到您的模块级build.gradle文件并将以下几行添加到代码中
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
这样就轻松解决了问题。检查此文档