duplicated class caused by mulitedex dependecy in Android Studio - android

thank you for your support.
My issue is : When I added the multidex dependecy and try to export the signed apk, I get this error :
Error:Execution failed for task
':androidKeyboardThemes:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/location/ActivityRecognition$1.class
My gradle dependecies are theses:
dependencies {
compile project(':cropper')
compile 'com.google.android.gms:play-services:+'
compile files('libs/StartAppInApp-2.4.7.jar')
compile files('libs/google-play-services.jar')
compile 'com.android.support:multidex:1.0.1'
}
I tried to delete one lib or jar at any time and build again but I couldn't get the job done.
Also I read all the unswer about duplicated class in stackoverflow but I failed again to solve my issue.
Any ideas?, thank you for your help.

dependencies {
compile project(':cropper')
compile 'com.google.android.gms:play-services:+' <-- choose either one
compile files('libs/StartAppInApp-2.4.7.jar')
compile files('libs/google-play-services.jar') <-- choose either one
compile 'com.android.support:multidex:1.0.1'
}
Whatever it is, please dont use play-services. inside compile 'com.google.android.gms:play-services:+' contains alot of dependencies.. see below.. using play-services may cause dex problem and heavy app. refer here

Related

Error while merging dex archives when using map_view with flutter android

So I had been searching forever for the solution to this and what my possible problem could be. I had narrowed down the source of the issue to the map_view plugin. It kept giving me errors with the dex file merge. I eventually found the following flutter issue report:
https://github.com/flutter/flutter/issues/12945
In one of the comments it says to go into the ExternalLibraries>firebase_auth>android>build.gradle and change the dependencies from:
dependencies {
compile 'com.google.firebase:firebase-core:11.0.+'
compile 'com.google.firebase:firebase-auth:11.0.+'
compile 'com.google.firebase:firebase-database:11.0.+'
}
to:
dependencies {
compile 'com.google.firebase:firebase-core:11.+'
compile 'com.google.firebase:firebase-auth:11.+'
compile 'com.google.firebase:firebase-database:11.+'
}
and to do that for some other gradle files as well... This solution actually cause my app to break when I had map_view removed.
Later I discovered that the dependencies in map_view build.gradle file looked like the following:
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.4-2'
compile 'com.google.android.gms:play-services-maps:11.+'
}
I changed it to:
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.4-2'
compile 'com.google.android.gms:play-services-maps:11.0.+'
}
Now it finally works.
Here is an image of the location of the dependency to change:
Screenshot
I hope this helps someone. Also, if there is anyone that could explain why this fixed the issue, I would greatly appreciate it!
Thanks

com.android.build.api.transform.TransformException: java.util.zip.ZipException

I imported some existing Eclipse based Android projects into Android Studio. Along, the way I fixed several issues and I am hitting this one last issue (hopefully):
Execution failed for task ':myapp:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/mypackage/myapp/BuildConfig.class
Here are dependencies:
module1:
dependencies {
provided files('src/main/libs/opencv.jar')
}
module2:
dependencies {
compile files('libs/autobanh.jar')
compile files('libs/libjingle_peerconnection_java.jar')
}
module3:
dependencies {
compile 'com.google.code.gson:gson:2.2.1'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services:+'
compile files('src/main/libs/gcm.jar')
}
module4:
dependencies {
compile project(':module3')
compile 'com.google.android.gms:play-services:+'
}
Finally the App:
dependencies {
compile project(':module1')
compile project(':module2')
compile project(':module3')
compile project(':module4')
compile 'com.android.support:support-v4:23.4.0'
compile files('libs/AndroidSwipeLayout-v1.1.8.jar')
compile 'com.android.support:appcompat-v7:23.4.0'
}
How do I fix this? I tried the following so far:
transformClassesWithJarMergingForDebug,com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
Execution failed for transformClassesWithJarMergingForDebug'. (Volley)
with no help. Any thoughts?
The error says
duplicate entry: com/mypackage/myapp/BuildConfig.class
BuildConfig is a class generated for each module (Android library or application) according to package name specified in its manifest.
Make sure all your modules have a unique package name in their AndroidManifest.xml

packageAllDebugClassesForMultiDex - duplicate entry "Escaper.class"

How does this happen when I try to deploy? In what library is this class ?
Note: It compiles and builds just fine, but this error shows up only when I try to deploy.
:myProject:packageAllDebugClassesForMultiDex FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':myProject:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/gdata/util/common/base/Escaper.class
These are the dependencies in my project, required by 4 different modules:
compile files('libs/gson-1.7.1.jar')
compile files('libs/httpmime-4.1.1.jar')
compile files('libs/icu4j-4_8_1_1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/twitter4j-core-3.0.5.jar')
compile files('libs/comscore.jar')
compile files('libs/javabase64-1.3.1.jar')
compile files('libs/libGoogleAnalytics.jar')
compile files('libs/urbanairship-lib-2.1.2.jar')
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v4:23.0.1'
Just like Mamata Gelanee said in the comments, the solution is to use maven repos instead of .jar's in /libs.
I've gotten rid of all jar's in my /libs folder and replaced it with maven repos and now it all builds and deploys fine.

:app:dexDebug on adding libGoogleAnalyticsServices

On trying to run my project, I get the following error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_67\bin\java.exe'' finished with non-zero exit value 2
I am adding the google analytics jar file from here. The issue goes away if I remove this line compile files('libs/libGoogleAnalyticsServices.jar') from the dependencies in the build.gradle
Is 1libGoogleAnalyticsServices.jar` interfering with something else I have in my dependencies?
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.1'
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/newrelic.android.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.google.android.gms:play-services:7.5.0'
compile('de.keyboardsurfer.android.widget:crouton:1.8.5#aar') {
}
compile ("com.doomonafireball.betterpickers:library:1.6.0")
compile ("com.doomonafireball.betterpickers:library:1.6.0") {
transitive = true
exclude group: 'com.android.support', module: 'support-v4'
}
compile project(':circularImageView')
}
This error could also indicate that you've hit the 65k method limit in Android.
If this is the case, then you have 3 options
Selectively use the parts of the play-services library that are required. This library itself will bring you close to the limit.
Let Progaurd minimize your application.
Use Multi-dex to split your dex index.
These guides will help you to achieve the options above;
http://googleadsdeveloper.blogspot.ie/2015/01/reducing-google-play-services-impact-on.html
https://developer.android.com/tools/building/multidex.html
Per the page you linked:
Important: This document describes a legacy version of the SDK. New users should use the latest SDK.
As the latest SDK is included in your 'com.google.android.gms:play-services:7.5.0' dependency, the two are overlapping and causing issues when building your application. You should instead follow the getting started guide for Google Analytics v4

Duplicate files while including butterknife with gradle

I have a basic Android app that I created with Android Studio, and I'm having problems adding butterknife to my build. I get this error:
Error:: duplicate files during packaging of APK C:\apps\orion\app\build\apk\app-debug-unaligned.apk
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor
File 1: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
File 2: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
My dependencies look like this:
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.jakewharton:butterknife:4.0.1'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:appcompat-v7:+'
compile project(':lib')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Later versions of the plugin will tell you how to fix this. I think we introduced the fix in 0.8 so you should probably upgrade. Then the fix is to put this in your build.gradle
android {
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
This will exclude this file from the packaging which is fine since it's not actually needed in the APK.
That's because you wrote compile for dagger-compiler, replace it with provided and the issue will be fixed.
compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
The best option in version >= 0.9.1 of Gradle build tools is probably:
android {
packagingOptions {
pickFirst 'META-INF/services/javax.annotation.processing.Processor'
}
}
For more, see the Android Tools Project page: New Build System.
Edit:
One last note here if you start having problems with generated code, make sure to structure your dependencies properly. I ended up removing any exclusion of the Processor line and structuring my annotation processed dependencies like:
compile "org.parceler:parceler-api:0.2.15"
apt "org.parceler:parceler:0.2.15"
and
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
If after applying above given solutions you still face the same issue as I was, then if you are using glide library then change the version of the glide to it's max.
eg.
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

Categories

Resources