今天在Android Studio中编译工程的时候,遇见了一个奇怪的问题,报错如下:
Error:Execution failed for task ‘:app:transformResourcesWithMergeJavaResForDebug’.
More than one file was found with OS independent path ‘META-INF/DEPENDENCIES’
大概意思就是工程生成了不止一个META-INF/DEPENDENCIES文件,看起来是因为多个 jar 包里包含了同样的文件(DEPENDENCIES.txt),导致打包时因为担心相互覆盖问题而提示出错
在网上很容易就找到了解决方法,即在报该编译错误的module的build.gradle中加入如下配置项,排除掉中间生成的DEPENDENCIES.txt文件
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
添加后的部分build.gradle文件如下:
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.liuning.bitcoin"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
原文地址:https://blog.csdn.net/realliuning/article/details/80010591