Android gradle在打包httpmime期间构建重复文件

时间:2015-08-14 09:31:48

标签: android android-studio

当我尝试构建我的android项目时,我收到此错误。首先我得到一个错误,由于AndroidMultiPartEntity.java中的问题我无法运行,所以我添加了

compile "org.apache.httpcomponents:httpmime:4.2.3"

在依赖项中。很多错误都消失了,但发生了这个错误。

    Information:Gradle tasks [:app:assembleDebug]

Error:duplicate files during packaging of APK C:\Users\AkerbergE\AndroidStudioProjects\incident\app\build\outputs\apk\app-debug-unaligned.apk
    Path in archive: META-INF/NOTICE.txt
    Origin 1: C:\Users\AkerbergE\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpmime\4.2.3\118ae1bc7f3aeeddfe564f0edfd79c11d09d17d1\httpmime-4.2.3.jar
    Origin 2: C:\Users\AkerbergE\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpcore\4.2.2\b76bee23cd3f3ee9b98bc7c2c14670e821ddbbfd\httpcore-4.2.2.jar
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'META-INF/NOTICE.txt'
      }
    }
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/NOTICE.txt
    File 1: C:\Users\AkerbergE\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpmime\4.2.3\118ae1bc7f3aeeddfe564f0edfd79c11d09d17d1\httpmime-4.2.3.jar
    File 2: C:\Users\AkerbergE\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpcore\4.2.2\b76bee23cd3f3ee9b98bc7c2c14670e821ddbbfd\httpcore-4.2.2.jar
Information:BUILD FAILED
Information:Total time: 3.903 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console

我的build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    packagingOptions {
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/NOTICE.TXT'
    }

    defaultConfig {
        applicationId "com.example.akerberge.incident"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile "org.apache.httpcomponents:httpmime:4.2.3"
}

1 个答案:

答案 0 :(得分:4)

实际上在您的代码中已经写了

exclude 'META-INF/NOTICE.TXT'

而不是写:

exclude 'META-INF/NOTICE.txt'

因此,您的build.gradle文件如下:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.akerberge.incident"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

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

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile "org.apache.httpcomponents:httpmime:4.2.3"
}