有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

gradle Android Studio 0.4复制到APK METAINF/LICENSE中的重复文件。文本

将Studio从0.3.7更新到0.4.0后,我无法编译我的项目。我在stackoverflow上找到了一个解决方案:Duplicate files copied (Android Studio 0.4.0)

我将我的项目更新为gradle 0.7++,但我不知道下一个字符串应该放在哪里:

安卓 {

    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中开发


共 (6) 个答案

  1. # 1 楼答案

    添加:

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

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

  2. # 2 楼答案

    加上

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

    内置。格拉德尔

  3. # 3 楼答案

    注意!!可能违反开源许可证

    不包括执照。txt文件如上所述,您可能会违反一些开源许可证,因为同意将其添加到源代码中是开源许可证中的一个常见点。 最好检查一下你的开源许可证

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

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

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

  4. # 4 楼答案

    根据新版gradle,我面临着同样的问题,见build。gradle文本格式适合我:

    我的libs文件夹中有两个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')
    }
    
  5. # 5 楼答案

    把dependecies放在最上面,把packageporations放在最后面,对我来说很管用

    apply plugin: 'android'. 
    

    这是我的身材。gradle在应用文件夹中

    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'
        }
    }
    

    编辑:几乎所有操作系统许可证都有义务在项目中“包含许可证副本”。这意味着,你必须在你的项目中包含你使用的所有操作系统许可证的副本。在格拉德尔“排除”他们,就违反了许可证

    将他们排除在项目之外可能不是最好的选择。 感谢R.S.提供的信息

  6. # 6 楼答案

    您可以通过将以下代码添加到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'
        }
    }