I have used 2 third party aar dependencies in my Android Project and
they both are using same Encoding Library called org.spongycastle.util.
But problem here is when i compiled it it shows an Error on Gradle
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException:java.util.zip.ZipException: duplicate entry: org/spongycastle/util/encoders/Base64.class
I tried to exclude one dependency from aar on Gradle complie by
compile(name: 'libraryname', ext: 'aar') {
exclude group: 'org.spongycastle.util'
}
But no luck of solving issue :(
Any help would be appreciated to exclude or ignore one dependency
It looks like the jar file org.spongycastle.util itself contains the duplicate entry. I've seen this same issue in an xmlbean jar file. Android however doesn't like the duplicate entry. One way to get around this is to download that particular jar file and delete one of the duplicate entries and add the modified jar to your libs folder. Additionally, you'll need to exclude it from the appropriate compile dependency it is associated with. You'll need to test to be sure that deleting one of the duplicates doesn't break anything. If the contents of the two duplicate classes are equivalent, then deleting one of the duplicates wouldn't have any consequence.
Related
I added Allibaba Push SDK to my Android project by adding the following module:
com.aliyun.ams:alicloud-android-push.
Then I tried to add the AliPay SDK in order to use payment via AliPay by downloading the following aar file:
alipaySdk-15.7.4-20200228192259 (this is the latest version according the the AliPay docs).
After adding both modules, the project won't compile due to several duplicate classes that exist in both modules.
I tried excluding the classes this way:
implementation(name: 'alipaySdk-15.7.4-20200228192259', ext: 'aar') {
exclude group: 'com.ut.device.UTDevice', module: 'alicloud-android-push'
}
com.ut.device.UTDevice is one of the duplicated classes..
But the duplicate message still persist for this class.
I also try to exclude the whole package (com.ut.*) but that didn't work either.
Anyone knows how to resolve this?
Thanks
I´m using multiple Calendar libraries for a demo aplication for android.
Including Flexible Calendar and Caldroid, both uses Infinite View Pager library, and it gives me Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' because f the duplicated class files:
java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/antonyt/infiniteviewpager/InfinitePagerAdapter;
So I enabled multidex and I was trying to exlude that library from one of those libraries but I can´t get the expected result.
I tried:
compile ('com.p_v:flexiblecalendar:1.2.1'){
exclude group: 'com.antonyt.infiniteviewpager', module: 'library'
}
and this
compile ('com.p_v:flexiblecalendar:1.2.1'){
exclude group: 'com.antonyt.infiniteviewpager'
}
and this
compile ('com.p_v:flexiblecalendar:1.2.1'){
exclude group: 'antonyt.infiniteviewpager'
}
But it doesn´t work. Im still getting the MultiDex error
Which one is the right way to acomplish this?
It can't work since these libs don't have the module com.antonyt.infiniteviewpager inside.
You can check the dependencies in the build.gradle of each library.
Also you can find the source of the InfinitePagerAdapter in each library (check link1 and link2).
Since the libraries seems to be not updated and quite easy to build you can download one of these as a local module in your project avoiding the duplicate.
I am getting duplicate library error on Gradle, One of the aar file i have added in my project has come up with the http-client-library library.
Now i need to remove this library from this SDK library file, because some other library is also using it.
I have tried following.
compile(name: 'SDK-app-1.0.0', ext: 'aar'){
exclude module: 'httpclient'
}
but it does not effect it, I can still see httpclient library in the sub module of SDK-app library.
I am unable to understand what should i need to add here? Is it a Module or library, or should i set transitive=true to remove this library from the aar file.
and When i try to add this library in my project
Duplicate zip entry
[android-async-http-1.4.9.jar:com/loopj/android/http/AsyncHttpClient$1.class])
If you know the compile statement
The easiest way of figuring this thing out is getting the compile statement you would usually add the dependency to your project.
Then you can take it apart to get the group and the module. Like so:
Identify first colon
Identify second colon
Everything from the beginning to the first colon is group
Everything between first and second colon is module
Excluding the dependency would be as easy as:
compile 'some.imaginary:library:4.8.15', {
exclude group: 'com.google.dagger', module: 'dagger'
}
If you don't know the compile statement
Things get a bit more complicated (but not much) if you don't have your compile statement. You can either:
Try to figure out the module and the group looking for the artifact online. For example in the Maven repository search engine. If you look at the Maven dependency you can see the groupId tag which represents your group and the artifactId tag which represents your module.
Or you can use gradle locally:
Open Terminal pane in your Android Studio:
Type in: ./gradlew androidDependencies
Find the row that relates to the library you're trying to exclude and split it the same way I did in the first example:
I am using the shadow plugin for Gradle to generate modified jars for Dagger 2. The jar files are generated as expected, but when I add the jars as dependencies to my proyect i get
Error:Execution failed for task ':transformClassesAndResourcesWithSyncLibJarsForRelease'.
> java.util.zip.ZipException: duplicate entry: META-INF/maven/com.google.dagger/dagger/pom.properties
To give toy the context of my case: I have an app with the next structure
CoreLib
|
Lib1
|
App
CoreLib and Lib1 uses these jar files generated by shadow to replace dagger2. But when running the app I get the previous exception in Lib1.
I add the jars like this in both libraries
apt files('libs/two-daggers-compiler-1.0.0.jar')
compile files('libs/two-daggers-library-1.0.0.jar')
Any ideas??
The solution for my problem was that I had to exclude the duplicated files.
I added this to my application buid.gradle and the problem was solved.
packagingOptions {
exclude 'META-INF/maven/com.google.dagger/dagger/pom.xml'
exclude 'META-INF/maven/com.google.dagger/dagger/pom.properties'
}
I added it in the android block
I'm pretty new to the Gradle build system and Android Studio and cannot quite figure out how to resolve this issue. My build is failing with:
* What went wrong:
Execution failed for task ':cyanEngine:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: javax/annotation/ParametersAreNullableByDefault.class
If I do Ctrl + N and search for ParametersAreNullableByDefault. One reference is pointing to External Libraries | jsr305-1.3.9. The other is pointing to classes.jar under xwalk_core_library.
xwalk_core_library is referenced in my xwalk_cordova module via:
{
android{
dependencies{
compile 'org.xwalk:xwalk_core_library:11.40.277.7'
}
}
And my app's gradle dependencies has:
compile project (':xwalk_cordova')
It seems like I need to get rid of the External Library, but I'm not sure where it's coming from.
Any pointers on how to resolve this?
Update:
I figured out the external reference was coming from Guava, referenced in the application build.gradle via compile ('com.google.guava:guava:11.0.2'). Just updating to Guava version 18.0 seems to get me past this for now. Guess the newer version no longer depends on jsr.
Still, I feel like I'll run into this again. Basically, we had two 3rd party libraries depending on the same library. What's the best way to clean this up?
I noticed for robolectic, there is an exclude, I'm guessing for similiar reasons:
testCompile('org.robolectric:robolectric:3.0-rc2') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
I'm curious how this statement works and don't quite understand the Gradle docs. What is this statement saying? Where do 'group' and 'module' come from?