Error:duplicate files during packaging of APK Android Studio Error

android, android-studio, java

Solution

Well you are missing the flow of build gradle. As you are trying to use 2 `android {..}` snippet it is not detecting the 2nd one. As a result your exclusion of duplicate meta files are not working.

Possible solution:

Just change the order of your build gradle like below:

    apply plugin: 'com.android.library'    
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }
    }
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.code.gson:gson:2.2.4'
    compile "org.apache.httpcomponents:httpcore:4.4.1"
    compile "org.apache.httpcomponents:httpmime:4.3.6"


}

If it still didn't work then check out the following:

Is it your library build gradle? I excluded my duplicate meta files from my main projects build gradle. So make sure to exclude the meta files from build gradle of app module rather than library module.

Problem

Am getting an unexpected error in Android studio while running the app,following is the error message which am getting Error:duplicate files during packaging of APK /home/jithu/libs/android/android/aa/app/build/outputs/apk/app-debug-unaligned.apk Path in archive: META-INF/DEPENDENCIES Origin 1: /home/jithu/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.6/cf8bacbf0d476c7f2221f861269365b66447f7ec/httpmime-4.3.6.jar Origin 2: /home/jithu/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.1/f5aa318bda4c6c8d688c9d00b90681dcd82ce636/httpcore-4.4.1.jar Am pasting my build.gradle file also ``` apply plugin: 'com.android.library' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:+' compile 'com.google.android.gms:play-services:6.5.87' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.mcxiaoke.volley:library:1.0.15' compile 'com.google.code.gson:gson:2.2.4' compile "org.apache.httpcomponents:httpcore:4.4.1" compile "org.apache.httpcomponents:httpmime:4.3.6" } android { packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } // ... } ```

Original source

Related problems