Android Gradle 在 APK META-INF/license.txt 中复制的重复文件

标签 android gradle spring-android

我将向我的 Android 应用程序中添加 Spring 的 RESTful Web 服务支持,如此处所述 https://spring.io/guides/gs/consuming-rest-android/ .

这是顶级 build.gradle 配置:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

这是我的 app/build.gradle 配置:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example"
        minSdkVersion 8
        targetSdkVersion 17
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    dependencies {
        compile 'com.android.support:appcompat-v7:+'
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
        compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
    }

    packagingOptions {
        exclude 'META-INF/NOTICE' // will not include NOTICE file
        exclude 'META-INF/LICENSE' // will not include LICENSE file
    }

}

现在它失败并出现以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/license.txt
    File1: user\.gradle\caches\modules-2\files-2.1\org.springframework.android\spring-android-rest-template\1.0.1.RELEASE\e132d929bd181941f79b0d63edafb8a86ae6fd33\spring-android-rest-template-1.0.1.RELEASE.jar
    File2: user\.gradle\caches\modules-2\files-2.1\org.springframework.android\spring-android-core\1.0.1.RELEASE\e68f0e8e4b636ee30c4de58953be38d9b72a5e3b\spring-android-core-1.0.1.RELEASE.jar

我做错了什么以及如何解决?

最佳答案

在您的应用级 gradle 文件中写入以下行

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

关于Android Gradle 在 APK META-INF/license.txt 中复制的重复文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37586800/

相关文章:

android - grails spring安全认证 token 问题

gradle - 如何使用格拉德脚本在 war 构建中添加WEB-INF/lib jar

android - 在 list 上声明条件许可

android - 如何从 Android 应用程序向 Rails 应用程序发送 POST 请求?

带代理的 Android Spring RestTemplate

android - java.lang.NoClassDefFoundError : org. springframework.web.client.RestTemplate 错误

android - TableRow 中以编程方式添加的元素的权重不起作用

android - 为什么 Android xml 中的 moSTLy 值是 8 的倍数?

java - 如何显示任意数字到小数点后 5 位

android - 如何从 Gradle 控制 Android 模拟器