3

hi im new in android development, i am trying to build my apk but i got this erorr. and i update my gradle and i got duplicate copy. how can 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 

and here's my build.gradle is this the error comes?

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:2.4.1@aar'
    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:1.1.0@aar'
    compile 'com.crashlytics.android:crashlytics:1.+'
}
Denver Bautista
  • 111
  • 1
  • 1
  • 7
  • Possible duplicate of [How do I resolve "Duplicate files copied in APK META-INF/\*"](http://stackoverflow.com/questions/33923461/how-do-i-resolve-duplicate-files-copied-in-apk-meta-inf) – user1643723 Nov 17 '16 at 04:56

4 Answers4

6

I had the same or at least a very similar problem today with our React Native app. The problem was only on my Mac though. The only plausible explanation we could think of was that I updated a bunch of Android Studio tools and then gradle couldn't build properly with our dependencies. Anyways after excluding the pom.properties and pom.xml from okhttp I kept getting the same error but it turns out that I just had to exclude even more files. This is my complete 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'
}
tech4242
  • 2,348
  • 2
  • 23
  • 33
0

to solve your problem please add this to your build gradle

packagingOptions {
    exclude 'META-INF/pom.properties' /*OR*/ 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
}
Kosh
  • 6,140
  • 3
  • 36
  • 67
0

It seems like okhttp and crashlytics don't work together in newer gradle versions (2.10 in my case). I fixed this by updating the crashlytics to a newer version (which is now called Fabric).

mjurekov
  • 37
  • 3
0
packagingOptions 
{
   exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
   exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
}

Please check for correct path "com.squareup.okhttp/okhttp/pom.properties" in your errorlog.