安卓 Gradle 复制的文件在 APK META-INF/license.txt.



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

您可以在应用 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'
}

让我知道它是否有效。

相关内容

最新更新