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.
Related
I have a native android project with a lot of submodules and custom flutter library that added as a submodule as well and dependency set up as described here: option B with settings.gradle
the issue is that some submodules are uses exoplayer, and flutter library uses it as well. so, while building I got a lot of dependency issue:
Duplicate class com.google.android.exoplayer2.video.spherical.Projection$SubMesh found in modules jetified-exoplayer-core-2.10.1-runtime (com.amazon.android:exoplayer-core:2.10.1) and jetified-exoplayer-core-2.10.1-runtime (com.google.android.exoplayer:exoplayer-core:2.10.1)
it seems force does not working in this case:
configurations.all {
resolutionStrategy.force 'com.google.android.exoplayer:exoplayer-core:2.10.1'
}
how can I exclude exoplayer from flutter lib?
Only option I found for now is to build .arr and exclude from here, but it not working for me as flutter library also is in development.
replace
implementation project(':flutter')
with
implementation(project(":flutter")) {
exclude module: 'exoplayer-core'
exclude module: 'exoplayer-hls'
exclude module: 'exoplayer-dash'
exclude module: 'exoplayer-smoothstreaming'
}
"(" and ")" around "project" is required
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 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'
}
}
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 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).