Android Studio 0.4复制 APK META-INF/LICENSE.txt 中复制的文件

在我将 Studio 从0.3.7更新到0.4.0之后,我无法编译我的项目。我找到了一个关于堆栈溢出的解决方案: 复制的重复文件(Android Studio 0.4.0)

我把我的项目升级到了0.7级 + ,但我不知道下一个字符串该放在哪里:

android {


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

我的日志猫: 日志

Execution failed for task ':Prog:packageDebug'.
> Duplicate files copied in APK META-INF/LICENSE.txt
File 1: /home/scijoker/AndroidStudioProjects/ProgProject/Prog/libs/httpclient-4.1.1.jar
File 2: /home/scijoker/AndroidStudioProjects/ProgProject/Prog/libs/httpclient-4.1.1.jar

在 ubuntu 13.04中进行开发

95857 次浏览

我有一个类似的错误,并解决了它没有 packingOptions()exclude的功能。我添加了两个依赖项,但其中一个是第一个依赖项的子组。这导致了错误,一旦我删除其中之一,我得到了一个干净的构建。我建议在依赖块中检查类似的错误。

将依赖项放在顶部,将 packageOptions 放在末尾对我来说很有效。

apply plugin: 'android'.

Here is my full build.gradle at the app folder.

dependencies {
compile 'com.android.support:support-v4:+'
compile files('libs/apache-mime4j-0.6.jar')
compile files('libs/httpmime-4.0.jar')
}


android {
compileSdkVersion 19
buildToolsVersion "19.0.1"


defaultConfig {
minSdkVersion 7
targetSdkVersion 10
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-    rules.txt'
}




packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}

EDIT: Almost all OS licence include the obligation to "include a copy of the licence" into your project. So this means, that you have to include a copy of all OS licences you use into you projects. By "excluding" them in gradle, you violate the licences.

将它们排除在项目之外可能不是最佳选择。 谢谢你的信息。

加上

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

建筑,梯度

I was facing the same problem as per new version of gradle, Below 建造,分级 text format work for me :

我的文件夹里有两个 Jackson 罐子。

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"


defaultConfig {
applicationId "com.omtlab.myapplication"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'libs/jackson-core-asl-1.9.13.jar'
exclude 'libs/jackson-mapper-asl-1.9.13.jar'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}


dependencies {
//compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/jackson-core-asl-1.9.13.jar')
compile files('libs/jackson-mapper-asl-1.9.13.jar')
}

Adding:

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

对我来说,比尼亚姆 _ 埃塞俄比亚的解决方案可能是最安全的

Attention!! Possible OpenSource license violation.

如果像上面建议的那样排除了 Licse.txt 文件,你可能会违反一些开源许可协议,因为这是开源许可协议中的一个共同点,即同意将它添加到你的源代码中。 最好检查一下你的开源许可证。

Update: 在找到更好的解决方案之前,使用

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

这样你至少履行了一部分许可义务

你也可以试试:

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

同时插入这个代码

android{


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

如果在 错误中显示,请确保

> 以 APK META-INF/许可证复制的重复档案

然后加上

 android{


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


}

如果在 错误中显示

> 以 APK META-INF/驾照复制的重复档案

然后加上

 android{


packagingOptions{
exclude 'META-INF/LICENSE'
}


}

如果在 错误中显示

> 以 APK META-INF/许可证复制的重复档案

然后加上

 android{


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


}

简而言之,CASE 和文档 FORMAT (. txt)非常重要。

(Android Studio 1.1.0中也存在此错误)

You can fix it by adding the following code to project/app/build.gradle:

android {
// Fixed build error : Duplicate files copied in APK META-INF/xxx
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
}

当同时使用 java-jwtjackson-core时,使用以下内容:

exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-annotations/pom.properties")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-annotations/pom.xml")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-databind/pom.properties")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-databind/pom.xml")

这将帮助你解决问题

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

I just add 2:

android{


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


}

这可能是非常糟糕的做法,但是如果您包含多个大型库,您可能会发现自己正在处理数以百计的这类冲突。

Listed below is a super-simple fix for such cases:

android {
....
packagingOptions {
// Allow the compilation process to choose the dependencies for us.
pickFirst "**"
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}

添加 build.gradle 文件和 syn 项目