Duplicate Entry during Android gradle build in Task :transformClassesWithJarMergingAndroidTest - android

I'm getting the following exception when building my Android app with Gradle:
Execution failed for task ':transformClassesWithJarMergingForGoogleGermanDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/hamcrest/BaseDesc
The problem seems to be that in my build.gradle file I have declared:
testCompile 'org.hamcrest:hamcrest-all:1.3'
androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
However, I need both dependencies for unit tests and integration tests. How to solve this?

The problem was that another jar (Mockito) included hamcrest-core as a transitive dependency. This module contains all classes under the package name org.hamcrest.*. Hence the conflict. The solution was:
configurations {
all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
As described here: https://docs.gradle.org/current/userguide/dependency_management.html Chapter 23.4.7

Try adding the exclude parameter for repeated entries.
androidTestCompile 'org.hamcrest:hamcrest-all:1.3' {
exclude module: 'BaseDesc'
}

buildTypes {
release {
multiDexEnabled true;
}
}
try this this should work

Related

Exclude package/classes from #aar, gradle dependency

I've following dependency added in build.gradle file.
compile 'com.aerisweather:aeris-maps-lib:2.0.0#aar'
It is from
https://oss.sonatype.org/content/repositories/comaerisweather-1027/com/aerisweather/aeris-maps-lib/2.0.0/
If you the see artifacts from following URL, It has android support v7 library classes.
https://oss.sonatype.org/#nexus-search;quick~aerisweather
I want to exclude that package when running/packaging the application. I'm unable to run/package the app due to duplicate class error.
I've tried adding configurations like this,
configurations {
all*.exclude group: 'com.android.support', module: 'appcompat-v7'
}
But this excludes it from entire project which leads me to many errors.
I've tried everything but still getting following error.
Error:Execution failed for task ':transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/appcompat/R$anim.class
This library has also as dependency support-v4 and mediarouter-v7.
You need to exclude them all from aeris-maps-lib and include as your own dependency.
def supportLibraryVersion = '25.0.1'
dependencies {
compile "com.android.support:support-v4:${supportLibraryVersion}"
compile "com.android.support:support-annotations:${supportLibraryVersion}"
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
//... other deps
compile ('com.aerisweather:aeris-maps-lib:2.0.0#aar', {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'mediarouter-v7'
})
}
PS.
aeris-maps-lib has also com.google.android.gms:play-services dependency, which is the whole Play Services package (it's large) and you will need to enable MultiDex or shrink code with proguard.
not a direct answer, but an advice.
The exclusion feature provided by gradle (exclude method invocation) doesn't work for contents inside local aar files as those contents aren't defined by dependency management and hence aren't recognised by the same.
As far as the dependency resolution is concerned, the aar file is an individual unit (including all the resources/classes within). So the file needs to be built in a way which doesn't include those entries; Or if the file is not built by you, you can unpack and omit the files in question and repack.
While there may be hackish ways to drop certain files using gradle (I couldn't find any reliable one yet), where we could possibly hook into some intermediate build steps and get rid of the files; but the generally advised best practise is to avoid packaging publicly available dependencies into the aar/jar to avoid duplicate entry issues and keep the aar/jar size smaller.

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'
}

Error compiling Android project after updating FindBugs to 3.0.1

After updating Findbugs plugin up to 3.0.1 version I can't compile multi module project in Android Studio. Also i use "com.google.code.findbugs:annotations:3.0.1" dependency for using FindBugs annotations (e.g. #SuppressFBWarnings).
I get following error while assembling project:
Execution failed for task ':presentation:packageAllDevelopDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: javax/annotation/CheckForNull.class
How can I fix it?
I resolved this issue, the cause was in adding to "com.google.code.findbugs:annotations:3.0.1" additional dependencies ('com.google.code.findbugs:jsr305:3.0.1' and 'net.jcip:jcip-annotations:1.0'). To fix it we need to exclude some transitive dependencies.
Replace:
dependencies {
compile "com.google.code.findbugs:annotations:3.0.1"
}
with
dependencies {
compile ("com.google.code.findbugs:annotations:3.0.1") {
exclude module: 'jsr305'
exclude module: 'jcip-annotations'
}
}
or with
dependencies {
compile ("com.google.code.findbugs:annotations:3.0.1") {
transitive = false
}
}
As suggested previously excluding module jsr305 worked for me, but I've used a different syntax due to importing a projest, not a module.
I was importing a library project present as indipendent project on my disk, so I had
compile project(path: ':shareLib')
To exclude module jsr305 I turned my code in
compile (project(path: ':shareLib')) {
exclude module: 'jsr305'
}

Android AssertJ 1.0.0 with Android gradle 1.1.1

Here is part of my build.gradle that has conflict:
...
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
...
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' )
...
The issue that I see in log:
WARNING: Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (21.0.3) and test app (20.0.0) differ.
Apparently it removes conflicting dependency from the classpath. I'm not sure if it is gradle or android gradle plugin.
I've tried next:
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
exclude group: 'com.android.support', module: 'support-annotations'
}
But I still have compilation errors so dependency is excluded.
I've tried next:
configurations.all {
resolutionStrategy {
// fail eagerly on version conflict (includes transitive dependencies)
// e.g. multiple different versions of the same dependency (group and name are equal)
failOnVersionConflict()
// force certain versions of dependencies (including transitive)
// *append new forced modules:
force 'com.android.support:support-annotations:21.0.3'
// *replace existing forced modules with new ones:
forcedModules = ['com.android.support:support-annotations:21.0.3']
}
}
But looks like it doesn't work since it is not failing on the first conflict and I still have compilation errors.
What will be your suggestions?
UPDATE What do I mean by removing dependency - I see a lot of compile errors that assertj not found
I ran into the same issue. This fixed it for me:
testCompile('com.squareup.assertj:assertj-android:1.0.0'){
exclude group: 'com.android.support', module:'support-annotations'
}
The accepted answer didn't work for me. However, adding the following did work for me:
androidTestCompile 'com.android.support:support-annotations:23.0.1'
and:
testCompile 'com.android.support:support-annotations:23.0.1'
Based on https://stackoverflow.com/a/29947562/2832027
You need to change:
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
exclude group: 'com.android.support', module: 'support-annotations'
}
to:
compile('com.squareup.assertj:assertj-android:1.0.0') {
exclude group: 'com.android.support', module: 'support-annotations'
}
Also ensure that your test folder is called test and not androidTest

Android studio gradle duplicate files dagger compiler

having strange problem after updating android studio to 0.4.0 and gradle plugin to 0.7.1 and gradle version to 1.9 with dagger compiler
build.gradle
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.android.support:support-v13:19.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.dagger:dagger:1.2.0'
compile 'com.squareup.dagger:dagger-compiler:1.2.0'
}
on build getting this error
Execution failed for task ':MyApplication:packageDebug'.
Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor
File 1: C:\Users\Mantas.gradle\caches\modules-2\files-2.1\com.squareup.dagger\dagger-compiler\1.2.0\22633bb84433e03d345a83e7b0c08c66768be30\dagger-compiler-1.2.0.jar
File 2: C:\Users\Mantas.gradle\caches\modules-2\files-2.1\com.squareup.dagger\dagger-compiler\1.2.0\22633bb84433e03d345a83e7b0c08c66768be30\dagger-compiler-1.2.0.jar
if dagger compiler lines is commented everything works fine
how can i solve this problem?
thanks
EDITED
fixed problem, check
https://plus.google.com/+HugoVisser/posts/7Wr3FcdNVxR
If you know which files are being duplicated you can always compile them with exceptions like this:
dependencies {
compile('com.squareup.dagger:dagger:1.2.0') {
exclude module: 'moduleName' //by artifact name
exclude group: 'groupName' //by group
exclude group: 'com.unwanted', module: 'moduleName' //or by both
}
compile 'com.squareup.dagger:dagger-compiler:1.2.0'
}
Just be sure that when you are doing this you enclose the dependancy in () to use the enclosure or it wont work.

Categories

Resources