1. 程式人生 > >More than one file was found with OS independent path 'META-INF/DEPENDENCIES'

More than one file was found with OS independent path 'META-INF/DEPENDENCIES'

今天在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' } }