Duplicate jar entry-android - android

I added 3rd party .aar file to my app. its runs smoothly without any issue. But when going to create APK file i get duplicate entry error
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForQaRelease'.
> java.io.IOException: Can't write [/Volumes/***/**/PROJECT/app/build/intermediates/transforms/proguard/qa/release/0.jar] (Can't read [/Users/ayeshdon/.gradle/caches/transforms-2/files-2.1/934a6f302e2712d6028d37a9dc4ccd20/jars/libs/commons-lang3-3.3.2.jar(;;;;;;;**.class)] (Duplicate jar entry [org/apache/commons/lang3/AnnotationUtils$1.class]))
My Gradle file is like this:
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation (project(":LIBRARYNAME"))
What is wrong here?

Whatever that "3rd party .aar file" may be, it complains about some Duplicate jar entry [org/apache/commons/lang3/AnnotationUtils$1.class]; therefore it's either:
implementation (project(":LIBRARYNAME")) {
exclude group: "org.apache.commons", module: "commons-lang3"
}
Or:
implementation fileTree(dir: "libs", include: ["*.aar", "*.jar"]) {
exclude group: "org.apache.commons", module: "commons-lang3"
}

Related

Duplicate class * found in modules (Android, gradle)

My gradle.properties file contains this:
android.useAndroidX=true
android.enableJetifier=true
Below is my gradle file code:
packagingOptions {
exclude "**/attach_hotspot_windows.dll"
exclude "META-INF/licenses/**"
exclude "META-INF/AL2.0"
exclude "META-INF/LGPL2.1"
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
//Adyen
implementation "com.adyen.checkout:3ds2:4.7.1"
implementation "com.adyen.checkout:card-ui:3.8.3"
implementation "com.adyen.checkout:redirect:4.7.1"
//Firebase imports
implementation 'com.google.firebase:firebase-crashlytics:18.2.7'
implementation 'com.google.firebase:firebase-analytics:20.0.2'
implementation 'com.google.firebase:firebase-messaging:23.0.6'
//UI imports
etc. imports
}
When I added //Adyen imports I started to get error message like this:
Duplicate class com.adyen.checkout.core.BuildConfig found in modules jetified-checkout-core-4.7.1-runtime (com.adyen.checkout:checkout-core:4.7.1) and jetified-core-v3-3.8.3-runtime (com.adyen.checkout:core-v3:3.8.3)
Duplicate class com.adyen.checkout.core.api.BaseHttpUrlConnectionFactory found in modules jetified-checkout-core-4.7.1-runtime (com.adyen.checkout:checkout-core:4.7.1) and jetified-core-v3-3.8.3-runtime (com.adyen.checkout:core-v3:3.8.3)
Duplicate class com.adyen.checkout.core.api.Connection found in modules jetified-checkout-core-4.7.1-runtime (com.adyen.checkout:checkout-core:4.7.1) and jetified-core-v3-3.8.3-runtime (com.adyen.checkout:core-v3:3.8.3)
android {
applicationVariants.all { variant ->
variant.getRuntimeConfiguration().exclude group: 'com.adyen.checkout:checkout-core:4.7.1', module: 'your-module'
}
}

Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback

I completely new to Android Development and can't seem to resolve this error:
"Error: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback"
This is my dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
implementation "android.arch.navigation:navigation-fragment:1.0.0-alpha01"
implementation "android.arch.navigation:navigation-ui:1.0.0-alpha01"
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
testImplementation 'junit:junit:4.12'
}
I've googled some and ended up on the developer page about "Resolve duplicate class errors", but I'm still not able to fix this. Help would be very much appriciated!
Option 1
Following worked for me
Add the following in your gradle.properties file
android.useAndroidX = true
android.enableJetifier = false
Option 2 (if above does't work)
Android studio -> Navigate -> Class
Check include non-project classes
Copy full class path android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
See where it is used. You may need to remove, one of them.
Option 3
you might be including package which is including modules as well so exclude the support-v4 module with following method
implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
exclude group: 'com.android.support', module:'support-v4'
}
You can analyze the conflicting modules using ./gradlew :YOURPROJECT:dependencies from a command line in your project repository.
Check especially your third party libraries for occurences of "com.android.support-":
Then exclude the conflicting modules from these dependencies like:
implementation ("com.jakewharton:butterknife:8.8.1") {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotation'
exclude group: 'com.android.support', module: 'support-compat'
}
Im using flutter, and Im adding some native libraries in android, I tried the solutions posted here, but the trick for me was android.enableJetifier = true instead false
So, adding the following code to the gradle.properties, my apps are running:
android.useAndroidX = true
android.enableJetifier = true
if you still getting error after
# gradle.properties
android.useAndroidX = true
android.enableJetifier = false
then you probably forgot about main activity that calling android.support.v7.app.AppCompatActivity
change it to androidx.appcompat.app.AppCompatActivity
adding following plugins
cordova plugin add cordova-plugin-androidx
cordova plugin add cordova-plugin-androidx-adapter
solved the problem for me
At least for me the issue was with the implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' dependency. I went into the menu in Android Studio to create a Blank Fragment in Kotlin just to see what that would look like and the dependency above was added.
Once i removed that dependency the error went away.
Some of your existing dependencies are using older versions of support library, try this
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' {
exclude group: 'com.android.support'
exclude module: 'support-v4'
}

duplicate entry: com/android/volley/AuthFailureError.class while compiling project in android studio

I am using external libraries payu money sdk and linkedin-sdk, both uses volley libraries, which while compiling project gives duplicate entry of AuthFailureError.class
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/android/volley/AuthFailureError.class"
i have also added following code to exclude module, but still same error
configurations{
all*.exclude module: 'com.android.volley'
}
please help
I stumbled upon this same error, and after reading this, I was able to solve it.
Try adding this line inside your app dir build.gradle file -
android{
configurations {
all*.exclude group: 'com.android.volley'
}}
Hope this helps.
I had this problem when I tried to generate the APK (release) and I solved it changing the linkedin-sdk build.gradle:
From:
dependencies {
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:21.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/volley.jar')
androidTestCompile('junit:junit:4.12') }
To:
dependencies {
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:21.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.volley:volley:1.0.0'
androidTestCompile('junit:junit:4.12') }
Add multiDexEnabled true in the defaultConfig section of your gradle file
Then,
compile 'com.android.support:multidex:1.0.1' in your dependencies
Finally add below in your application class:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Also, check if you are using volley.jar in your libs folder. If so, delete that jar file, and compile again. Sometimes, jar dependencies conflicts with those compiled using remote source.
This is an example how to exclude classes in dependencies when there is duplicate entry in gradle.
compile ('com.google.api-client:google-api-client-android:1.17.0-rc') {
exclude module: 'httpclient'
}
or try with your way just add some more text
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
So, now what you have to do is
Search CTRL+SHIFT+N in android studio for the class AuthFailureError.class
See which jar contains this and remove it like above (This is just as an example/You have to figure out the duplicate class and manually remove it)
just remove the duplicate jar file(note:use new version,delete old version) for importing "com.android.volley.AuthFailureError" in build.gradle. Then clean project and rebuild project and then run you will get result.
I had the similar issue while making build on Jenkins, weirdly it was working fine on my local machine. After adding below exclude it worked both on local machine and Jenkins.
android{
configurations {
all*.exclude group: 'com.android.volley'
}}
I have added configurations block to my app's build.gradle inside android section.
If it matter's Compile SDK version is 22 and Build Tools version is 25.0.0
This worked like a charm.
Okay I got my answer
On mac instead of control n, it is command 0 and the command i needed was
configurations {
all*.exclude module: 'volley-release'
}
Just remove your volley library from dependancy.
Try clean and rebuild project it works for me.
Ex. payusdk are also implementing volley library so that is the reason exception shows duplicate entry. I hope it works. because i also found this error and i do these things it works.
Thanks.
Use the below command in Android studio terminal to get the dependency conflict data - [Replace with your app Name]
./gradlew -q :<app>:dependencyInsight --dependency volley --configuration compile
If you are using latest Volley library from android [https://github.com/google/volley/releases], add below two lines in your build.gradle file under each of the compile library entries that has conflict.
Ex:
compile('com.xyz:abc:1.1.0-RELEASE') {
exclude module: 'library'
exclude group: 'com.mcxiaoke.volley'
}

Commons-Io Duplicate Entry Error Using Robospice and Android Studio

I've been working on the following issue for several hours, but haven't come up with a way to solve my problem. I've tried the following fixes from Stack Overflow (Android Studio update to 1.0 corrupts MultiDex and Duplicate Zip Entry after Gradle Plugin v0.13.1) but neither one of them worked.
I am getting the following error when trying to build my program:
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: org/apache/commons/io/CopyUtils.class
The error seems to indicate that commons-io is being included twice in the build process
I am using Android Studio and Gradle to include multiple Robospice dependencies. This is the dependencies section of my Gradle build file:
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile'com.google.api-client:google-api-client-android:1.19.0'
// You must install or update the Google Repository through the SDK manager to use this dependency.
// The Google Repository (separate from the corresponding library) can be found in the Extras category.
//compile 'com.google.android.gms:play-services:4.3.23'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.jakewharton:butterknife:${butterknifeVersion}"
compile 'com.sun.jersey:jersey-bundle:1.8'
compile 'com.google.code.gson:gson:2.3'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.0'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.0'
compile ('com.octo.android.robospice:robospice:1.4.14'){
exclude module: 'commons-io'
exclude group: 'commons-io'
}
compile ('com.octo.android.robospice:robospice-spring-android:1.4.14'){
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile ('com.octo.android.robospice:robospice-google-http-client:1.4.14'){
exclude module: 'xpp3'
exclude group: 'stax'
}
compile 'org.scribe:scribe:1.3.5'
compile files("$buildDir/native-libs/native-libs.jar")
}
Using the "gradlew -q dependencies app:dependencies" command to view the project's dependency tree indicates that com.octo.android.robospice:robospice:1.4.14 is dependent on the commons-io library. Here is the relevant snippet of the project dependency tree:
+--- com.octo.android.robospice:robospice:1.4.14
| \--- com.octo.android.robospice:robospice-cache:1.4.14
| +--- org.apache.commons:commons-lang3:3.3.2
| \--- org.apache.commons:commons-io:1.3.2
| \--- commons-io:commons-io:1.3.2
The dependency is still listed even though I excluded commons-io from all Robospice related dependencies in the gradle build file. I also tried changing the group name from commons-io to org.apache.commons, and that did not work either.
My project is at a standstill until I get this resolved, and I would appreciate any help I can get.
This is a known and fixed problem in Robospice, caused by an underlying Gradle 2.1 issue: https://github.com/stephanenicolas/robospice/issues/365. The fix is going to be released in the next version.
You can work around it by excluding org.apache.commons:commons-io from all Robospice dependencies, and include commons-io:commons-io:1.3.2 manually. Like this:
// workaround (https://github.com/stephanenicolas/robospice/issues/365)
// remove when robospice updates to 1.4.15+
compile ('com.octo.android.robospice:robospice-retrofit:1.4.14') {
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile ('com.octo.android.robospice:robospice-ormlite:1.4.14') {
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile 'commons-io:commons-io:1.3.2'
I guess this question needs a structured approach towards solving the issue which both of the above answers fail to provide.
Step 1: Find out which external library is causing duplicate zip entry. Run following command from terminal of Android Studio.
gradlew -q dependencies app:dependencies
In my case, image picking library ('net.yazeed44.imagepicker:imagepicker:1.3.0') was causing the duplicate entry.
Step 2: Add code to exclude commons-io only for that library
compile ('net.yazeed44.imagepicker:imagepicker:1.3.0'){
exclude group: 'org.apache.commons', module: 'commons-io'
}
Step 3: Include updated commons-io library.
compile 'commons-io:commons-io:1.3.2'
Now you are set to go.

Multiple dex files define Landroid/support/v4/ in android studio

I can integrate (add & work) with many libraries.
But as for ActionBarSherlock library, I have so many problems with it.
First Issue is the popular issue Multiple dex files define,
I know The duplicated android-support-v4.jar causes it, but I can not solve this issue now :
Error:Execution failed for task ':fitness:dexDebug'.
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
I followed the answer in same error. It used :
dependencies {
compile('...') {
exclude module: 'support-v4'
}
compile 'com.android.support:support-v4:18.0.+'
}
But I received Second Issue : unsupported Gradle DSL method found: 'exclude()'! error.
Therefore I changed build.gradle of main module like this:
//configurations {
// all*.exclude group: 'com.android.support', module: 'support-v4'
//}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':google-play-services')
compile files('/google-play-services/libs/google-play-services.jar')
compile (project(':actionbarsherlock')) {
exclude(module: 'support-v4')
}
compile 'com.android.support:support-v4:18.0.+'
}
Solved Second Issue, But still get First Issue Multiple dex files define error.
I read many topics, but can not solve First Issue now,
Please help me,
Thanks,
p/s : I can sync with Gradle successully, but when run, it get above errors.
I used Android studio 0.5.5
EDIT
build.gradle of ActionBarSherlock, it has only one android-support-v4.jar:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
setting.gradle like this :
include ':fitness', ':google-play-services',':actionbarsherlock'
#Garbriele : I updated new question, show build.gradle of project and build.gradle of main module
build.gradle of project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
build.gradle of main module after edited :
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar' // Get following error in this line
}
I got this error in below :
Okay, thanks for #Garbriele comment, I already fixed this by using this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar' // Get following error in this line
}
EDIT 2 When I put like this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:+'
}
Still get First Issue Multiple dex files define error.
What I want now is how to add com.google.android.gms:play-services library via Maven successfully,
Please help me,
Thanks,
UPDATE
After followed these steps :
Put the library via Maven in build.gradle of main module : compile 'com.google.android.gms:play-services:+'
Restart Android Studio
Sync project with gradle
No longer get this error again.
So strange,
When I setup my dependencies like this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:+'
}
I still get the First Issue Multiple dex files define error.
But after following these steps:
Put the library via Gradle in build.gradle of main module : compile 'com.google.android.gms:play-services:+'
Restart Android Studio
Sync project with gradle
I no longer get this error.
I had duplicate libraries in my libs directory:
$ ls -la libs/
total 80
drwxr-xr-x 5 wheel 170 25 Sep 22:09 .
drwxr-xr-x 10 wheel 340 25 Sep 22:07 ..
-rw-r--r-- 1 wheel 3736 25 Sep 21:36 ApiComponent.jar
-rw-r--r-- 1 wheel 28741 25 Sep 21:36 DependencyService.jar
-rw-r--r-- 1 wheel 3736 25 Sep 22:09 classes.jar
Removing classes.jar worked for me. I modified my DependencyService Project to produce DependencyService.jar instead of classes.jar causing the duplication.

Categories

Resources