【问题标题】:"Duplicate lib file copied in APK-META-INF/license.txt " error in Android StudioAndroid Studio 中的“在 APK-META-INF/license.txt 中复制的重复库文件”错误
【发布时间】:2015-11-01 22:45:49
【问题描述】:

我在项目中使用以下 2 个库 1. spring-core-3.1.0.RELEASE.jar 2. spring-web-3.1.0.RELEASE.jar

但 android studio 正在考虑上述库的重复条目并在打包时出错。


Error:duplicate files during packaging of APK E:\Code\iDoc\app\build\outputs\apk\app-debug-unaligned.apk
    Path in archive: META-INF/license.txt
    Origin 1: E:\Code\iDoc\app\libs\spring-core-3.1.0.RELEASE.jar
    Origin 2: E:\Code\iDoc\app\libs\spring-web-3.1.0.RELEASE.jar
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'META-INF/license.txt'
      }
    }
------------------------------------------------------------

有人遇到过类似的问题吗?

请针对此错误提出一些解决方法。

【问题讨论】:

标签: android android-studio


【解决方案1】:

转到您的 build.gradle 文件并添加以下行:

 packagingOptions {
    exclude 'META-INF/license.txt'
  }

就我而言,我必须像这样添加:

apply plugin: 'com.android.library'    
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    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'
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.code.gson:gson:2.2.4'
    compile "org.apache.httpcomponents:httpcore:4.4.1"
    compile "org.apache.httpcomponents:httpmime:4.3.6"


}

注意:

  1. 元文件不会影响应用程序的任何编程功能。元文件基本上包含文本信息,如开源库的法律声明、许可证等。排除它不会影响任何事情。

  2. 当我们使用多个第 3 方开源库时,有时 2 个或更多项目具有相同名称的文本文件(例如:License.txt 或 Notice.txt 或 dependencies.txt)。这会在构建期间导致冲突。在那一刻,我们强大的 android 工作室建议我们排除那些冲突的元文件。

【讨论】:

  • 我必须同时添加exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt'
  • 您也可以exclude 'META-INF/*'排除所有文件。
  • @Mohammad-Arman 禁止删除许可证文件/通知的许可证怎么样?
【解决方案2】:

我有最简单的 txt 文件解决方案。如果您删除依赖项中的所有 txt 文件。

只添加这个块。

packagingOptions {
    exclude '**/*.txt'
}

【讨论】:

    【解决方案3】:

    重要提示:排除文件时注意区分大小写

    我将此添加到我的 gradle 中,但它不起作用:

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    

    我遇到了错误:

    Duplicate files copied in APK META-INF/notice.txt
    

    所以解决方法是add META-INF/notice.txt

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
    }
    

    【讨论】:

      猜你喜欢
      • 2014-01-16
      • 2016-10-01
      • 2017-10-07
      • 2015-02-14
      • 2016-12-13
      • 1970-01-01
      • 2016-08-10
      • 2015-03-14
      相关资源
      最近更新 更多