【问题标题】:Android Gradle Duplicate files copied in APK META-INF/license.txt [duplicate]Android Gradle 在 APK META-INF/license.txt 中复制的重复文件 [重复]
【发布时间】:2017-10-07 04:11:04
【问题描述】:

错误:任务 ':app:transformResourcesWithMergeJavaResForDebug' 执行失败。 > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: 在 APK META-INF/LICENSE File1 中复制的重复文件:C:\Users\hdeka.gradle\caches\modules-2\文件-2.1\com.

【问题讨论】:

标签: javascript android android-studio-2.2


【解决方案1】:

您可以在应用的 gradle 文件中添加几行代码来消除该错误。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "YourAppId"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       }
    }
    // these are the lines that you have to add
    packagingOptions {
    exclude 'META-INF/LICENSE'
    //include below line if you are using firebase
    //exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

让我知道它是否有效。 :-)

【讨论】: