Anand Jain Anand Jain - 5 months ago 42
Android Question

Error:duplicate files during packaging of APK in android studio

when i try to run my app i faced unknown of error like this:-

Error:duplicate files during packaging of APK D:\andriod App\JsonArray\app\build\outputs\apk\app-debug-unaligned.apk
. and one of another problem come in like this:-


Error:Execution failed for task ':app:packageDebug'.

Duplicate files copied in APK META-INF/LICENSE.txt
File 1: D:\andriod App\JsonArray\app\libs\commons-logging-1.2.jar
File 2: D:\andriod App\JsonArray\app\libs\commons-codec-1.9.jar


apply plugin: 'com.android.application'android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "android.catalyst.com.jsonarray"
minSdkVersion 14
targetSdkVersion 23
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:23.0.1'}

Answer

You should add below code to your gradle file :

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

Edited :

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'commons-logging:commons-logging:1.2'
compile 'commons-codec:commons-codec:1.9'
}

Remove jar(commons-logging and commons-codec ) from libs folder and add this gradle dependency.

Thanks.