Duplicate entry error in my Android app - android

This error occurs when I sync the gradle file
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/client/android/camera/CameraConfigurationUtils.class
I tried cleaning the project, rebuilding the project and multidex, excluding the module.
My min sdk is 19. If greater than 20, multidex worked properly,
but in SDK 19 it didn't work.
This is my gradle build file:
apply plugin: 'com.android.application'
android
{
compileSdkVersion 24
buildToolsVersion '25.0.2'
defaultConfig
{
applicationId "com.example.prototype_01"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes
{
release
{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.google.android.gms:play-services-appindexing:9.6.1'
compile 'com.android.support:multidex:1.0.0'
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'com.google.zxing:core:3.2.0'
compile 'com.github.bumptech.glide:glide:3.5.1'
//compile files('libs/android-core-3.2.1.jar')
compile 'com.android.support:support-v4:24.2.1'
compile 'com.tsengvn:Typekit:1.0.0'
compile 'com.google.firebase:firebase-messaging:9.6.1'
}
apply plugin: 'com.google.gms.google-services'
What can be done to solve this issue?

It is not related to Multidex.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/client/android/camera/CameraConfigurationUtils.class
It means that you are adding the same class CameraConfigurationUtils.class twice.
Check your jar files.
If you have libs/android-core-3.2.1.jar you are adding twice the same class.
This class is inside the jar and inside the library compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'.
Remove the jar file from the libs folder.

duplicate entry: com/google/zxing/
You've added too many libraries. Try removing one at a time until your app can build.
Start with removing any conflicting Jar files from libs related to Zxing
Zxing core is not necessary, the embedded one already compiles it
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
// compile 'com.google.zxing:core:3.2.0'
Multidex / changing your SDK version isn't going to magically fix overlapping dependencies

Related

Generate Signed Apk Error Multidex

My app is working properly. There is no problem. i want to build generated signed apk. The problem is building take too long and completed with errors.
Please check the image. Thanks.
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
here my gradle;
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "umut.com.anyidea"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-messaging:9.6.0'
compile 'com.google.firebase:firebase-core:9.6.0'
compile 'com.google.firebase:firebase-crash:9.6.0'
compile 'com.google.android.gms:play-services:9.6.0'
compile 'com.google.android.gms:play-services-auth:9.6.0'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.afollestad.material-dialogs:core:0.9.0.1'
compile 'com.google.firebase:firebase-database:9.6.0'
compile 'com.google.firebase:firebase-auth:9.6.0'
compile 'com.firebaseui:firebase-ui-database:0.6.0'
}
apply plugin: 'com.google.gms.google-services'
In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.
From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs,
Please refer this document:
https://developers.google.com/android/guides/setup
for example if you need Google Account Login then just use :
com.google.android.gms:play-services-auth:9.6.1 not use compile 'com.google.android.gms:play-services:9.6.1'
just add this and try.
its works for me.
defaultConfig {
multiDexEnabled true
}
// multidex issues
compile 'com.android.support:multidex:1.0.0'
or
dexOptions {
javaMaxHeapSize "4g"
}
Have you add this in Application class
MultiDex.install(this);
Put this line in defaultConfig block
multiDexEnabled true
And add the following dependencies
compile 'com.android.support:multidex:1.0.0'
After this rebuild your project. Hopefully this should resolve your error.
Just remove unused libraries (or dependencies) from app's build.gradle file and again try to generate signed apk. It will work. :)

Duplicate dependency error for gms /analytics android studio 2.2rc2

My app Level Gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.mss.triplestar"
minSdkVersion 15
targetSdkVersion 23
multiDexEnabled true
}
//====================Add below two line=============
dexOptions {
javaMaxHeapSize "4g" //specify the heap size for the dex process
preDexLibraries = false //delete the already predexed libraries
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
// compile files('libs/libGoogleAnalyticsV2.jar')
compile 'com.google.android.gms:play-services-analytics:9.0.0'
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/vungle-publisher-adaptive-id-3.3.1.jar')
compile 'com.google.android.gms:play-services-ads:9.0.0'
compile project(':wheelLib')
compile 'com.google.android.gms:play-services:9.0.0'
// compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'com.scottyab:aescrypt:0.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:24.2.0'
}
My log output
Information:Gradle tasks [:app:assembleDebug]
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5 is ignored for release as it may be conflicting with the internal version provided by Android.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/analytics/internal/Command$1.class
Information:BUILD FAILED
Information:Total time: 2.579 secs
Information:1 error
Information:2 warnings
Information:See complete output in console
This is my log output i am trying to build and update my project but
it gives me this error if i removed analytic jar than i get easy
tracker error .please help i am stuck at this point getting no clue
.tried all the solutions .Thanks in advance
Since you are adding a legacy version of the Google Analytics SDK for Android you should remove it.
Remove:
compile files('libs/libGoogleAnalyticsServices.jar')
Also add the plugin to the bottom of your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
Also no reason to use both:
compile 'com.google.android.gms:play-services-ads:9.0.0'
compile 'com.google.android.gms:play-services:9.0.0'
and you shouldn't ever be using compile 'com.google.android.gms:play-services:9.0.0' as that includes every Google Play services library - only use the APIs you need.
change
buildToolsVersion "24.0.2" to 23.0.4

Gradle Build Run error (DebugUtils.class) in Android Studio 1.5

I'm getting the following error
Error:Execution failed for task
:app:transformClassesWithJarMergingForDebug.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/util/DebugUtils.class
I searched the entire day but couldn't found a proper answer which will solve my problem.
My app bulid gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.project.test"
multiDexEnabled true
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
// depend files
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-ads:+'
compile 'com.google.android.gms:play-services-identity:+'
compile 'com.google.android.gms:play-services-gcm:+'
compile files('libs/android-support-v4.jar')
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
}
I tried Clean and Rebuild, but that also not working.
Please help on this. Thanks in advance.
This issue happens when you add the same class twice.
In your project you are adding many times the support-v4 library.
remove android-support-v4.jar from libs folder
remove this line compile files('libs/android-support-v4.jar')
change the dependency of the library 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' because it uses an old support-v4.jar
Use:
compile ('com.github.JakeWharton:ViewPagerIndicator:2.4.1') {
exclude module: 'support-v4'
}
After doing some research it seams that com.github.JakeWharton:ViewPagerIndicator:2.4.1 is already importing the android-support-v4.jar, from here your duplicate error. In order to fix it I recommend you to do the following changes:
remove android-support-v4.jar from libs folder
remove from gradle file the line compile files('libs/android-support-v4.jar').
Hope it fixes your problem.

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' while using YouTube API

I'm using the YouTube SDK to play videos in a viewpager. As soon as I run the app, this error is thrown:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/youtube/player/internal/u.class
Manifest.xml:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.xxxxx.www.xxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
mavenLocal()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.thefinestartist:ytpa:1.2.1'
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
compile 'com.mxn.soul:flowingdrawer-core:1.2.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.xgc1986.android:parallaxpagertransformer:1.0.3'
compile('com.github.afollestad.material-dialogs:core:0.8.5.7#aar') {
transitive = true
}
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
}
I can't include
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
as viewpager uses support library v4
That error comes when any of your jar dependency have same class. Make sure you have not added support jar both as gradle and jar dependency. There might be duplicate references to the same API.
Try ./gradlew yourBuildVariantName --debug from the command line. You can safely remove it from the project or from your build file(s), clean using the command ./gradlew clean and rebuild the project(repeat if necessary).
Check this related SO questions Gradle Duplicate Entry: java.util.zip.ZipException and java.util.zip.ZipException: duplicate entry during packageAllDebugClassesForMultiDex.
I observed the same issue after Android Studio upgrade to version 2.2 Preview 6
Then I deleted lines:
compile(name: 'YouTubeAndroidPlayerApi', ext: 'jar')
and
flatDir { dirs 'libs'}
from two build.gradle files and the issue is gone.
Looks like 'libs' directory is built automatically now but I'm not able to find any confirmation on Google pages.
Add
dependencies {
compile 'com.android.support:support-v4:24.2.1'
}
in build.gradle file.

Duplicate Entry Google Gson

My error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
I'm trying to use Stripe and integrate it with retrofit. I have the Stripe lib build.gradle file and the app build.gradle file.
I dont see whats causing this error and I need the dependency in both build.gradle files because both Stripe and Retrofit use it.
app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.weaverprojects.stripe2"
minSdkVersion 21
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 project(':stripe')
//compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.code.gson:gson:2.3'
compile 'org.parceler:parceler:0.2.13'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup:otto:1.3.6'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
}
Stripe build.gradle:
apply plugin: 'com.android.library'
dependencies {
// compile 'com.stripe:stripe-java:1.15.1'
// compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/gson-2.2.4.jar')
compile files('libs/stripe-java-1.15.1.jar')
}
android {
compileSdkVersion 21
buildToolsVersion '23.0.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 21
multiDexEnabled = true
}
}
I do have the Stripe and GSON jar in the libs folder so I tried changing:
compile 'com.google.code.gson:gson:2.3'
to
compile files('../stripe/libs/gson-2.2.4.jar')
in the app's build.gradle.
What am I doing wrong?
Thanks in advance.
The root of the issue is that you're mixing a dependency on a jar via compile files('libs/gson-2.2.4.jar') and a maven artifact via compile 'com.google.code.gson:gson:2.3'.
When you reference the same maven artifact in separate parts of your project, Gradle is able to intelligently figure out that it shouldn't include both. But, Gradle is unable to figure out that the jar you're referencing is the same as the maven artifact you're referencing.
Solution
In Stripes build.gradle, change the lib reference to compile 'com.google.code.gson:gson:2.3', and delete gson-2.2.4.jar from your project entirely.
Either remove the line compile 'com.google.code.gson:gson:2.3'
or
Delete the gson jar from your lib folder. because you have included the library twice once in build file and in libs folder.

Categories

Resources