今天在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'
}
}
复制代码