I am trying to integrate custom framework.jar in my code and setting the priority of this new framework.jar file over android provided jar file, but while compiling the code I am getting below error :
Execution failed for task ':nuswypedev:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:org/apache/http/conn/ConnectTimeoutException.class
How to solve this issue?
This happens because your program jars or library jars contain multiple definitions of the listed classes.
You can check the dependencies by
./gradlew app:dependencies | grep "org.apache.httpcomponents:httpcore"
After you found the duplication, you can use reference below "exclude group" syntax to exclude one of them
Example:
dependencies {
implementation('log4j:log4j:1.2.15') {
exclude group: 'javax.jms', module: 'jms'
exclude group: 'com.sun.jdmk', module: 'jmxtools'
exclude group: 'com.sun.jmx', module: 'jmxri'
}
}
Related
Is there a way to exclude jar from aar? there are classes.jar and lint.jar in appcompat-1.2.0.aar . I want to exclude lint.jar when I implmentation 'androidx.appcompat:appcompat:1.2.0'
when I place implmentation 'androidx.appcompat:appcompat:1.2.0' to build gradle , my customized Lint rules will donot work. Because there is a lint.jar in appcomat.aar, so I want exclude lint.jar from appcomat.aar.
Because lint is just a jar in appcompat.aar, There is no lint dependency in pom.xml, So I cannot use blow code to exclude lint.jar :
implementation('androidx.appcompat:appcompat:1.2.0') {
exclude group: 'androidx.appcompat', module: 'lint'
}
You can use something like
configurations {
all*.exclude group: 'androidx.appcompat:appcompat', module: 'lint'
}
in your app level build.gradle file.
This basically excludes some of the modules inside the libraries which you do not need to use.
Group specifies the package name of the dependency you have imported, and module specifies the particular module that you wish to exclude.
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.
I am working on a project for a client. The project seems to work fine in the old Android Studio, but ever since I updated my studio to 2.2.2, I am getting the sync error when trying to run the app, the error message is as posted below.
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: /home/empressum/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient-android/4.3.5.1/eecbb0b998e77629862a13d957d552b3be58fc4e/httpclient-android-4.3.5.1.jar
File2: /home/empressum/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3/5b0002c5fb66867ca919be0fbd86de1cfaf76da7/httpmime-4.3.jar
You might also want to check if you have 2 references of the same library or .jar included and remove the duplicate reference.
Guess you are using dependency which is conflicting with androids supplied jars. Add
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
in your gradle.
Add following into respective build.gradle file
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}
}
You are using two many libraries files for http call instead use jar file on libs or add some dependency in gradle.
The error went when I downloaded the project zip file again and run it. But this time when Android Studio asked me to update the gradle file, I denied. I dont know if this explains the error, but now the project is running fine on any device I connect.
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 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.