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
Related
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
Good day.
After updating google repository in AndroidStudio, I have an issue
> Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry:
> android/support/v7/cardview/BuildConfig.class
I'm trying to exclude group android.support from play-services, it did not help.
When I started my project on another PC I have:
> Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry:
> android/support/annotation/AnimRes.class
my build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "ru.alexeyk.myevents"
minSdkVersion 14
targetSdkVersion 23
versionCode 16
versionName "1.121"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.github.nkzawa:socket.io-client:0.4.2') {
exclude group: 'org.json', module: 'json'
}
compile files('libs/sentry-1.1.4.jar')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.github.machinarius:preferencefragment:0.1.2'
compile 'com.edmodo:cropper:1.0.1'
compile 'com.makeramen:roundedimageview:2.1.1'
compile 'org.ocpsoft.prettytime:prettytime:4.0.0.Final'
compile 'com.yandex.android:mobmetricalib:2.00#aar'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
}
In terminal execute in root project folder:
./gradlew clean
It helped me.
AndroidStudio Menu:
Build/Clean Project
Update old dependencies
All the above not working for me.. Because I am using Facebook Ad dependency..
Incase If anybody using this dependency compile 'com.facebook.android:audience-network-sdk:4.16.0'
Try this code instead of above
compile ('com.facebook.android:audience-network-sdk:4.16.0'){
exclude group: 'com.google.android.gms'
}
Open your system command prompt/terminal -> Go to your Project folder path (root project folder ) -> Execute following command : command :- gradlew clean or ./gradlew clean
Make sure that all your gradle dependencies are of same version. -> Example :- your appcompat and recyclerview dependencies should have same version.
-> Change your gradle dependencies to same version like :-
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
-> Rebuild your project and it will work fine.
Use project root in terminal like this:-/Users/rajnish/Desktop/RankProjects/ProjectCloud
After that enter this command ./gradlew clean
It will work.
There may be different reason for reported issue, few days back also face this issue 'duplicate jar', after upgrading studio. From all stackoverflow I tried all the suggestion but nothing worked for me.
But this is for sure some duplicate jar is there, For me it was present in one library libs folder as well as project libs folder. So I removed from project libs folder as it was not required here. So be careful while updating the studio, and try to understand all the gradle error.
I got this error because I did not have the correct line in my build.gradle. I am using the org.apache.http.legacy.jar library, which requires this:
android{
useLibrary 'org.apache.http.legacy'
...
}
So check that you have everything in your gradle file that is required.
I resolved the issue by double checking the "libs" directory and removing redundant jars, even though those jars were not manually added in the dependencies.
see if their duplicate jars or dependencies your adding remove it and your error will be gone:
Eg:
if you add android:supportv4 jar and also dependency you will get the error so remove the jar error will be gone
I resolve this is by changing the version no of recyleview to recyclerview-v7:24.2.1.
Please check your dependencies and use the proper version number.
For me the issue was caused by com.google.android.exoplayer conflicting with com.facebook.android:audience-network-sdk.
I fixed the problem by excluding the exoplayer library from the audience-network-sdk :
compile ('com.facebook.android:audience-network-sdk:4.24.0') {
exclude group: 'com.google.android.exoplayer'
}
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.
I have an app using many modules such as facebookSDK, linkedInSDK etc. I needed to add one more module that is using volley library which is also used in linkedInSDK.
It builds successfully but causes:
Error:Execution failed for task ':splashActivity:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 2
this error.
app build.gradle:
compile(name: 'app-debug', ext: 'aar')
compile 'com.android.support:support-v4:22.2.0'
compile 'com.mcxiaoke.volley:library:1.0.17#aar'
compile 'com.android.support:appcompat-v7:22.2.0'
linkedInSDK build.gradle:
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/volley.jar')
As you can see, they both use volley library. When I remove one of them it throws cannot be resolved error in that module.
I tried
defaultConfig {
multiDexEnabled true
}
it didn't work.
Both app and linkedInSDK modules needs volley library. How can I build and run it successfully
I think some solution is present on the 'gradle' foram. can you please try this.
dependencies {
compile('packageName:name:version') {
//excluding a particular transitive dependency:
exclude module: 'name of excluing package' //by artifact name
}
}
"Happy Coding...!!!"
I solved it by moving my brand new module to the linkedInSDK and enabling multiDex. So I saw I had two problems, the first one is my project is over 65k Methods which needs multiDex, and library conflict between linkedInSDK and the new SDK.
So here is my linkedInSDK\build.gradle:
dependencies {
compile files('libs/volley.jar')
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
//compile 'com.mcxiaoke.volley:library:1.0.17'
compile(name: 'app-debug', ext: 'aar')
}
repositories {
flatDir {
dirs 'libs'
}
}
So the volley library is used in the same module without conflict. Yay!
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