首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android Gradle复制到APK META-INF/license.txt se.txt中的重复文件

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

Stack Overflow用户
提问于 2016-06-02 16:42:38
回答 5查看 61.5K关注 0票数 75

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

这是顶级build.gradle配置:

代码语言:javascript
复制
// 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配置:

代码语言:javascript
复制
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
    }

}

现在它失败了,并显示以下错误:

代码语言:javascript
复制
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

我做错了什么?如何修复它?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2016-06-02 16:45:19

在你的应用级gradle文件中写下下面的几行

代码语言:javascript
复制
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'
    }
}
票数 251
EN

Stack Overflow用户

发布于 2017-01-04 18:13:52

如果所选答案中的解决方案不能解决您的问题,请尝试添加

代码语言:javascript
复制
    exclude 'META-INF/ASL2.0'

也是。或者基本上,识别重复文件的名称并将其排除。上面的添加为我解决了这个问题。

票数 10
EN

Stack Overflow用户

发布于 2017-06-13 05:25:30

添加这些代码行对我很有帮助。

代码语言:javascript
复制
shadowJar {
    // Filtering shadow jar contents by file pattern.
    exclude 'schemaorg_apache_xmlbeans/attribute/**'
    exclude 'schemaorg_apache_xmlbeans/attributegroup/**'
    exclude 'schemaorg_apache_xmlbeans/element/**'
    exclude 'schemaorg_apache_xmlbeans/identityconstraint/**'
    exclude 'schemaorg_apache_xmlbeans/javaname/**'
    exclude 'schemaorg_apache_xmlbeans/modelgroup/**'
    exclude 'schemaorg_apache_xmlbeans/namespace/**'
    exclude 'schemaorg_apache_xmlbeans/src/**'
    exclude 'schemaorg_apache_xmlbeans/system/sXML*/**'
    exclude 'schemaorg_apache_xmlbeans/system/s8C3F193EE11A2F798ACF65489B9E6078/**'
    exclude 'schemaorg_apache_xmlbeans/type/**'

    exclude 'repackage/**'

    exclude 'LICENSE.txt'
    exclude 'NOTICE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/maven/**'

    // these are only needed when handling Visio files, remove it if you would like to use Visio support
    dependencies {
        exclude(dependency('com.github.virtuald:curvesapi'))
        exclude(dependency('commons-codec:commons-codec'))
    }

    // Relocate javax dependencies so Android does not choke
    relocate 'javax.xml.namespace', 'org.apache.poi.javax.xml.namespace'
    relocate 'javax.xml.stream', 'org.apache.poi.javax.xml.stream'
    relocate 'javax.xml.XMLConstants', 'org.apache.poi.javax.xml.XMLConstants'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37586800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档