TransformException after migrating to Android Studio - android

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

Related

Android Studio dex.DexException:

Randomly got this error during my build (debug or production) in the morning.
com.android.dex.DexException: Multiple dex files define Lcom/crashlytics/android/answers/shim/R
Execution failed for task ':app:transformClassesWithDexForDebug'.
>...
It has been 10hours and I have tried:
1) Updated my Android SDKs
2) Updated my Google Repository
3) Updated everything else as well.
4) Cleaned and Rebuild the project with no errors.
5) Went through my external dependency tree, didn't find any duplicate libraries.
Here is my gradle content:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "######.####"
minSdkVersion 19
targetSdkVersion 25
versionCode 53
versionName "1.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.androidmapsextensions:android-maps-extensions:2.3.0'
compile 'com.google.android.gms:play-services-gcm:10.2.1'
compile 'com.google.android.gms:play-services-location:10.2.1'
compile 'com.google.android.gms:play-services-maps:10.2.1'
compile 'com.google.android.gms:play-services-places:10.2.1'
compile 'com.google.maps.android:android-maps-utils:0.5'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'org.jsoup:jsoup:1.9.2'
compile 'com.github.lzyzsd:circleprogress:1.1.0#aar'
compile 'com.google.code.gson:gson:2.7'
compile 'io.branch.sdk.android:library:2.+'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-crash:10.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:1.0.1'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.edmodo:rangebar:1.0.0'
compile 'com.appyvet:materialrangebar:1.3'
compile 'com.facebook.fresco:fresco:0.14.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
compile 'com.android.support:recyclerview-v7:25.0.0'
}
apply plugin: 'com.google.gms.google-services'
Running out of ideas and google result pages for a solution. Does anybody experienced find something wrong with the libraries I use or the versions?
Thanks!
remove this line = compile 'com.android.support:design:25.0.0'
if it doesn't work please add
dexOptions {
preDexLibraries = false }
to your build.gradle file
Solution found.
Looking at the error I googled and found this.
Then went to the Branch documentation and found this here which stated:
Note that if you don’t plan to use the Fabric Answers integration, you
can use the following line:
compile ('io.branch.sdk.android:library:2.+') {
exclude module: 'answers-shim'
}
This answers-shim is also in the stacktrace.
I wonder where is that module then duplicated?

Android Error duplicate entry: com/google/android/gms/internal/zzai$zza.class

I am currently having some trouble running my project.
duplicate entry: com/google/android/gms/internal/zzai$zza.class
The error is saying that I have a duplicate dependency, but I can't see a duplicate anywhere!
The error appears on this line of code:
compile 'com.google.android.gms:play-services-ads:8.4.0'
It says that it has found versions 9.8 and 8.4. I only see version 8.4 though.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.tedrasoft.templategoogle"
minSdkVersion 15
targetSdkVersion 23
versionCode=7
versionName="1.6"
multiDexEnabled true
manifestPlaceholders = [manifestApplicationId : "${applicationId}",
onesignal_app_id : "ed282ffa-1e9e-4dd8-9edc-cfdcbe8376bd",
onesignal_google_project_number: "3902815545"]
}
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile files('libs/chartboost.jar')
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.facebook.android:audience-network-sdk:4.+'
compile 'com.onesignal:OneSignal:2.+#aar'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-analytics:+'
compile 'com.google.android.gms:play-services-location:+'
compile files('libs/jackson-annotations-2.1.0.jar')
compile files('libs/jackson-core-2.1.0.jar')
compile files('libs/jackson-databind-2.1.0.jar')
}
In my case, it's because of the
compile 'com.facebook.android:audience-network-sdk:4.+'
I change it to this:
compile ('com.facebook.android:audience-network-sdk:4.+'){
exclude group:"com.google.android.gms"
}
No more problem!
Make these versions match... so 8.4.0, not + which pulls the latest 9.8 I think, now?
compile 'com.google.android.gms:play-services-analytics:+'
compile 'com.google.android.gms:play-services-location:+'
Also, these are 1) unneccessary lines (because of compile fileTree), and 2) you should make them like the others and not use jar files.
compile files('libs/jackson-annotations-2.1.0.jar')
compile files('libs/jackson-core-2.1.0.jar')
compile files('libs/jackson-databind-2.1.0.jar')
Upgrade google play services (maps, location and gcm) from 9.0.0 to 9.2.0
compile 'com.google.android.gms:play-services-location:9.2.0'
compile 'com.google.android.gms:play-services-maps:9.2.0'
compile 'com.google.android.gms:play-services-gcm:9.2.0'
Then add this dependency:
compile 'com.google.android.gms:play-services-places:9.2.0'

my eclipse project error when migrated to android studio?

this my problem over day, my log result is Error:(2) Attribute "titleTextStyle" has already been defined
my project use actionbarsherlock, google_play_service, and another lib, i want to move my old project to android studio. i already tried many link in this site but doesn't work. this my gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.ltvie.test"
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
}
dependencies {
compile project(':lib')
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.code.gson:gson:2.1'
compile 'com.google.guava:guava:11.0.1'
compile 'com.google.protobuf:protobuf-java:2.2.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/google-api-client-1.10.3-beta.jar')
compile files('libs/google-api-client-android2-1.10.3-beta.jar')
compile files('libs/google-http-client-1.10.3-beta.jar')
compile files('libs/google-http-client-android2-1.10.3-beta.jar')
compile files('libs/google-oauth-client-1.10.1-beta.jar')
compile files('libs/jackson-core-asl-1.9.4.jar')
compile files('libs/json-org.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/universal-image-loader-1.9.3-SNAPSHOT.jar')
compile files('libs/WebSocket.jar')
}
i read some tutorial that my problem cause I use appcompat-v7 and actionbarsherlock in same time, but in my dependencies nothing appcompat-v7, i try to remove actionbarsherlock then the error disappear but appear more error. how to solve my problem, thanks.

Error ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry:

I am developing android application for Home Automation using gradle in Android Studio. There is no problem when I build the project, but when I try to run the project, there is an error like this:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: org/apache/http/params/CoreConnectionPNames.class
Here is my build.gradle codes:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.cpl"
minSdkVersion 15
targetSdkVersion 23
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:23.0.1'
compile files('libs/android.jar')
compile files('libs/bcprov-jdk15on-1.47.jar')
//compile files('libs/google-play-services.jar')
//compile files('libs/google-play-services1.jar')
compile files('libs/httpclient-4.2.3.jar')
compile files('libs/httpcore-4.3.jar')
compile files('libs/nineoldandroids-library-2.4.0.jar')
compile files('libs/Pubnub-Android-3.7.2.jar')
compile files('libs/renderscript-v8.jar')
compile files('libs/sun.misc.BASE64Decoder.jar')
compile files('libs/universal-image-loader-1.9.2.jar')
//compile files('libs/android-support-multidex.jar')
compile 'com.android.support:multidex:1.0.1'
}
please help me to solve this problem. Thank you anyway
Please change your gradle dependencies as following :
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:23.0.1'
compile files('libs/renderscript-v8.jar')
compile files('libs/sun.misc.BASE64Decoder.jar')
compile 'org.apache.httpcomponents:httpclient:4.2.3'
compile 'org.bouncycastle:bcprov-jdk15on:1.47'
compile 'org.apache.httpcomponents:httpcore:4.3'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.pubnub:pubnub-android:3.7.2'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
compile 'com.android.support:multidex:1.0.1'
Note :
In Gradle when we do not use gradle dependency and if our libs folder dependencies contains duplicate class then
java.util.zip.ZipException: duplicate entry
This exception occurs.
So Whenever you add dependencies then if possible then try maximum to use maven dependencies.
Thank you.!!
Try adding following dependencies:
compile 'com.google.android.gms:play-services-plus:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'

duplicate entry: com/google/android/gms/common/SupportErrorDialogFragment.class

I am creating project in android studio with multi dex support . I am getting error : java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/SupportErrorDialogFragment.class . I know this issue is for duplicate class. But unable to figure out that which class is getting duplicate and how to fix it. Below are the code of my build.gradle. Please suggest. Thanks.
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.rtpl.create.app.v2"
minSdkVersion 14
targetSdkVersion 19
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':pageIndicator')
compile project(':materialDesign')
compile project(':zxingLib')
compile project(':datetimepickerlibrary')
compile project(':facebookSDK')
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/Android_SDK.jar')
compile files('libs/Android_SDK_component.jar')
compile files('libs/crashlytics.jar')
compile files('libs/google-play-services.jar')
compile files('libs/im.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/linkedin-j-android.jar')
compile files('libs/PayPal_MECL.jar')
compile files('libs/prime-0.6.1.jar')
compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/signpost-jetty6-1.2.1.1.jar')
compile files('libs/socialauth-4.2.jar')
compile files('libs/socialauth-android-2.6.jar')
compile files('libs/twitter4j-core-3.0.5.jar')
compile files('libs/universal-image-loader-1.9.1-SNAPSHOT-with-sources.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile files('libs/gcm.jar')
compile 'com.android.support:multidex:1.0.0'
}
You have conflicting dependencies in your build.gradle, meaning multiple dependencies containing the same classes:
compile 'com.google.android.gms:play-services:+'
compile files('libs/google-play-services.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/gcm.jar')
All of these components are provided by Google Play Services (the first one in the list). So you should only declare Google Play Services once, preferably only the components you're using instead of the full package: See "Selectively compiling APIs into your executable" https://developers.google.com/android/guides/setup
Chances are you won't even need multidex after you simplify your project dependencies.
Also (unrelated), I'm wondering what are these dependencies, if it's the Android framework itself you can remove them:
compile files('libs/Android_SDK.jar')
compile files('libs/Android_SDK_component.jar')

Categories

Resources