I tried to import a working Eclipse Android project to Android Studio. I am working on Mac with the latest version of Android Studio. When I try to build, it keeps on displaying this error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/api/client/http/AbstractHttpContent.class
The class generating this issue is in the com.google.http-client:google-http-client-gson:1.20.0 library, in the com.google.api.client.http package. I tried many things with the app.gradle file, such as excluding the com.google.api.client.http group but nothing works. Here is my app.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.time2"
minSdkVersion 17
targetSdkVersion 19
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions.encoding = 'ISO-8859-1'
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.http-client:google-http-client-gson:1.20.0'
compile 'com.google.code.gson:gson:2.1'
compile files('libs/commons-io-2.4.jar')
compile files('libs/google-api-client-1.18.0-rc.jar')
compile files('libs/google-api-client-android-1.18.0-rc.jar')
compile files('libs/google-http-client-1.18.0-rc.jar')
compile files('libs/google-http-client-android-1.18.0-rc.jar')
compile files('libs/google-oauth-client-1.18.0-rc.jar')
compile files('libs/httpcore-4.3.3.jar')
compile files('libs/httpmime-4.3.6.jar')
compile files('libs/json-simple-1.1.1.jar')
compile files('libs/jsr305-1.3.9.jar')
compile 'com.stripe:stripe-android:+'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}
You should avoid manually adding in libs to your project.
E.g. change compile files('libs/commons-io-2.4.jar') compile files('libs/google-api-client-1.18.0-rc.jar') compile files('libs/google-api-client-android-1.18.0-rc.jar') compile files('libs/google-http-client-1.18.0-rc.jar') compile files('libs/google-http-client-android-1.18.0-rc.jar') compile files('libs/google-oauth-client-1.18.0-rc.jar') compile files('libs/httpcore-4.3.3.jar') compile files('libs/httpmime-4.3.6.jar') compile files('libs/json-simple-1.1.1.jar') compile files('libs/jsr305-1.3.9.jar') to compile 'commons-io:commons-io:2.4' compile 'com.google.api-client:google-api-client:1.18.0-rc' compile 'com.google.api-client:google-api-client-android:1.18.0-rc' compile 'com.google.http-client:google-http-client:1.18.0-rc' compile 'com.google.http-client:google-http-client-android:1.18.0-rc' compile 'com.google.oauth-client:google-oauth-client:1.18.0-rc' compile 'org.apache.httpcomponents:httpcore:4.3.3' compile 'org.apache.httpcomponents:httpmime:4.3.6' compile 'com.googlecode.json-simple:json-simple:1.1.1' compile 'com.google.code.findbugs:jsr305:1.3.9'
Please verify that these are the correct packages. Let us know what you find after updating?
The library 'com.google.http-client:google-http-client-gson:1.20.0'
is composed of the following nine modules:
google-http-client google-http-client-android google-http-client-appengine google-http-client-xml google-http-client-protobuf google-http-client-jdo google-http-client-jackson google-http-client-jackson2 google-http-client-gson
Some of these e.g. google-http-client
is included again in tour dependencies as a jar
. Hence the duplicate entry.
Check this link for getting the setup right when using google-http-java-client
. It has step by step instruction - Setup Instructions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With