We an android projects with lots of flavors. One flavor includes an aar that bundles android-async-http inside the aar file.
The problem is we already define the compile dependency for all our flavors:
compile 'com.loopj.android:android-async-http:1.4.6'
and that results in failed builds with the error:
> com.android.build.api.transform.TransformException: java.util.zip.ZipException:
duplicate entry: com/loopj/android/http/AssertUtils.class
I'm looking to try to exclude that dependency for just one flavor. Something like:
freeCompile('com.loopj.android:android-async-http:1.4.6') {
exclude = true
}
Anyway to do that without defining the dependency for every flavor?
Related
My Android Studio main project uses two library projects (let's call it A and B). both A and B use my custom library (let's call C).
Upon compiling the main project, I got the following error:
Error:Execution failed for task
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/mycompany/Tracking.class
How can I exclude the offending class so that it does not get included more than once?
Thanks.
It means that there is the same class Tracking.class in both dependence libraries.
This errors usually occurs when importing .jar files.
Firstly, try to remove this in your build.gradle.
compile fileTree(dir: 'libs', include: '*.jar')
If it does not work, you should exclude the common module in one of these two libraries:
compile (A or B) {
exclude module: C
}
Please provide details of your build.gradle file if these above solution does not work.
I'm trying to figure out if it's possible to exclude class files or use pickfirst for classes in a jar file dependency. We always seem to run into issues where third party libs package up jars in aar files instead of using gradle dependencies and therefore cause duplicate file zip exceptions:
like this:
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/codec/StringEncoderComparator.class
The only solution we've found so far is to unzip the aar, delete the offending jar, and rezip it back up. Is there a way to just exclude the jar or class from gradle?
Looking at the source it seems like I should be able to use packaging options. So I've tried various combinations of pick first and exclude but no luck:
packagingOptions {
pickFirst '**/StringEncoderComparator.class'
pickFirst 'org/apache/commons/codec/StringEncoderComparator.class'
pickFirst 'org/apache/commons/codec/*'
}
Use resolutionStrategy.
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
apply plugin: 'java' //so that there are some configurations
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()
// prefer modules that are part of this build (multi-project or composite build) over external modules
preferProjectModules()
// force certain versions of dependencies (including transitive)
// *append new forced modules:
force 'asm:asm-all:3.3.1', 'commons-io:commons-io:1.4'
// *replace existing forced modules with new ones:
forcedModules = ['asm:asm-all:3.3.1']
// add dependency substitution rules
dependencySubstitution {
substitute module('org.gradle:api') with project(':api')
substitute project(':util') with module('org.gradle:util:3.0')
}
// cache dynamic versions for 10 minutes
cacheDynamicVersionsFor 10*60, 'seconds'
// don't cache changing modules at all
cacheChangingModulesFor 0, 'seconds'
}
}
First of all, I got this:
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/nostra13/universalimageloader/cache/disc/DiskCache.class
I use the UniversalImageLoader jar in my app project, but also I have a library module which also uses the exact same jar.
I tried to add something like that to my app build.gradle file:
compile (project(':imagesubsampling')){
exclude group: 'com.nostra13.universalimageloader', module: 'com.nostra13.universalimageloader'
}
or
compile (project(':imagesubsampling')){
exclude group: 'com.nostra13', module: 'universalimageloader'
}
or
compile (project(':imagesubsampling')){
exclude group: 'com.nostra13.universalimageloader'
}
Nothing works.
Therefore, my question is:
compile (project(':imagesubsampling')){
<What to write here to exclude jar file from this library>
}
Is there a better solution to get rid of duplicates?
What to write exactly?
I met this issue when there're more than one universal
image loader reference in your project(maybe in the libs folder, or in dependencies of the project,sublibs).
Check again all build.gradle files(in android studio) in your project.Keep one and delete all others would solve the problem.
I have an SDk in the form of an aar in my project's lib folder. I am attempting to add it as a dependency in my project's build.gradle.
dependencies {
...
compile(name:'mySDK', ex:'aar')
...
}
However, when I try to rebuild gradle, I get the following:
Error:(48, 0) No such property: ex for class: org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency_Decorated.
> java.util.zip.ZipException: duplicate entry: org/apache/http/impl/cookie/IgnoreSpecFactory.class
I unziped mySDK and confirmed that httpclient-android-4.3.5.1.jar is a library used in mySDK (this jar contains org.apache.http...).
I then updated my gradle to try and exclude this library.
dependencies {
...
compile(name:'mySDK', ex:'aar'){
exclude(group: 'org.apache.http', module: 'httpclient-android-4.3.5.1')
}
...
}
I've also tried excluding:
exclude module: 'httpclient'
exclude(group: 'org.apache.http', module: 'httpclient-android')
exclude(group: 'org.apache.http', module: 'httpclient')
Unfortunately, I'm still receiving the same java.util.zip.ZipException. Any idea how I can solve this?
You can't do it with an aar file and a flat repo.
You can do it only it you are using a maven dependency. In this case you have a pom file which describes the dependencies (with modules and group).
In an aar there isn't any pom file which describes that the jar file is a dependency called httpclient-android-4.3.5.1 for example.
Usually the aar file doesn't contain the dependencies.
The best option is to have this aar in a maven repo in order to exclude dependencies.
Since it is not possible, an alternative could be to unzip the aar file, remove the jar dependency and repack the aar (it is a simple zip file).
I have a project named MyProject.
It includes 2 library projects abc.aar and xyz.aar.
These both library projects uses and have one common jar dummy.jar (package name: com.example.dummy).
When I include both library projects, it gives me
android java.util.zip.ZipException: duplicate entry com/example/dummy/DummyClass$1.class
I have tried following things -
configurations {
// to avoid double inclusion
all*.exclude group: 'com.example.dummy'
}
and this too
compile (name:'abc', ext:'aar'){
transitive = false
exclude module: 'libs/dummy*.jar'
exclude group: 'com.example.dummy'
exclude module: 'com.example.dummy'
}
Please suggest to avoid double inclusion of dependency jar because of multiple dependency library project using same jar.
My both library projects are not on any repositories.