Java – Duplicate files copied in APK META-INF

Duplicate files copied in APK META-INF… here is a solution to the problem.

Duplicate files copied in APK META-INF

Hi, I’m

new to Android development and I’m trying to build my apk but I’m getting this error. I updated my gradle and I got a copy. How do I fix this error?

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/ com.squareup.okhttp/okhttp/pom.properties
    File1: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.squareup.okhttp\okhttp\2.0.0\4c8d1536dba3812cc1592090dc20c47a4ed3c35e\okhttp-2.0.0.jar
    File2: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.crashlytics.android\crashlytics\1.1.13\e821eafa1bf489a26bdb71f95078c26785b37a1\crashlytics-1.1.13.jar 

This is my build.gradle, is this a bug?

buildscript {
    repositories {
        maven { url 'http://download.crashlytics.com/maven' }
    }

dependencies {
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

defaultConfig {
        applicationId "com.mymonas.ngobrol"
        minSdkVersion 14
        targetSdkVersion 20
        versionCode 1
        versionName "0.9.0.68"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {

mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'], exclude: 'android-support-v4.jar')
    compile project('libs:floatlabel')
    compile 'com.android.support:support-v4:21.0.0'
    compile 'com.android.support:support-v13:21.0.0'
    compile 'com.squareup.retrofit:retrofit:1.7.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.1'
    compile 'com.google.android.gms:play-services:6.1.11'
    compile 'com.viewpagerindicator:library:[email protected]'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.makeramen:roundedimageview:1.3.0'
    compile 'com.andreabaccega:android-form-edittext:[email protected]'
    compile 'com.crashlytics.android:crashlytics:1.+'
}

Solution

Today, I’m having the same or at least very similar issues with React Native apps. But the problem is only with my Mac. The only plausible explanation we can think of is that I updated a bunch of Android Studio tools and then gradle didn’t build correctly with our dependencies. Anyway, after excluding pom.properties and pom.xml from okhttp, I keep getting the same error, but it turns out I just need to exclude more files. This is my full packagingOptions::in build.gradle

packagingOptions {
  exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.properties'
  exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
  exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.xml'
  exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}

Related Problems and Solutions