【问题标题】:Error : Gradle: Duplicate files during packaging of APK错误:Gradle:打包 APK 期间文件重复
【发布时间】:2016-06-19 02:07:28
【问题描述】:

在我的 gradle android 应用程序中,当我运行应用程序时出现以下错误。

错误:Gradle:打包 APK /home/WorkSpace/MyProject/app/build/outputs/apk/app-debug-unaligned.apk 时出现重复文件 错误:Gradle:任务“:app:packageDebug”执行失败。 在 APK META-INF/license.txt 中复制的重复文件 文件1:/home/.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 文件 2:/home/.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 文件。 build.gradle:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'
}
}
 apply plugin: 'com.android.application'


 repositories {
  jcenter()
 }

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.myproject.app"
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_6
    targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/notice.txt'
}
}

 dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:gridlayout-v7:23.2.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'joda-time:joda-time:2.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.android.support:design:23.2.0'

 }

我该如何解决这个错误?请帮帮我。

【问题讨论】:

    标签: gradle android-gradle-plugin spring-android


    【解决方案1】:

    你的构建文件中已经有了这个:

    packagingOptions {
        exclude 'META-INF/notice.txt'
    }
    

    您也可以在此处添加license.txt

    【讨论】:

      【解决方案2】:

      在包装选项和依赖项中添加以下行。

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

      在依赖项中使用如下。

      dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      compile 'com.android.support:appcompat-v7:23.2.0'
      compile 'com.android.support:design:23.2.0'
      compile 'com.android.support:cardview-v7:23.2.0'
      compile 'com.android.support:recyclerview-v7:23.2.0'
      compile 'com.j256.ormlite:ormlite-core:4.48'
      compile 'com.j256.ormlite:ormlite-android:4.48'
      compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
      compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
          exclude module: 'spring-core'
      }
      compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
      compile 'org.apache.commons:commons-io:1.3.2'
      compile 'joda-time:joda-time:2.3'
      compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
      compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
      compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
      compile 'com.google.code.gson:gson:2.6.2'
      }
      

      我认为这将解决您的问题。

      【讨论】:

        猜你喜欢
        • 2014-01-07
        • 2013-09-14
        • 2015-12-20
        • 2015-05-02
        • 2014-04-23
        相关资源
        最近更新 更多