I am Developing an android application and using a library say A. and I have another library say B which internally uses A. Because of this, I get Duplicate zip entry error on my build. How do i exclude libraries from 3rd party libraries or how do i get around this issue?
You can exclude the modules you don't need from a dependency with exclude module:
compile (project(':B')) {
exclude module: 'A'
}
Related
I work on an app with multiple Dynamic Modules.
In order to add the video download's feature to my app, I need to add the ExoPlayer UI dependency (com.google.android.exoplayer:exoplayer-ui:2.11.1) to my base module.
Since I already have this dependency in my player module, I have this compilation error message :
Modules 'base' and 'player' contain entry 'res/layout/exo_playback_control_view.xml' with different content.
Since I can't rename the ExoPlayer generated layout file, I've tried to get ride of this file from my base module since I only need it into my player module.
So far I've tried :
sourceSets {
main.res.srcDirs += 'src/main/res'
main {
res {
exclude 'res/layout/exo_playback_control_view.xml'
exclude 'layout/exo_playback_control_view.xml'
exclude 'exo_playback_control_view.xml'
exclude 'library/ui/src/main/res/layout/exo_playback_control_view.xml'
}
}
}
And
packagingOptions {
exclude 'res/layout/exo_playback_control_view.xml'
exclude 'layout/exo_playback_control_view.xml'
exclude 'exo_playback_control_view.xml'
exclude 'library/ui/src/main/res/layout/exo_playback_control_view.xml'
}
Any of these works.
I am not comfortable with Gradle as you probably can see.
I've also opened an issue on the ExoPlayer Github repository.
Does anyone have another idea to avoid this compilation error?
I recently added implementation 'com.google.android.play:core:1.6.4' as a dependency in my android project and now Intellij is complaining that Program type already present: androidx.exifinterface.R. What does this mean and how do I fix this?
Note: this is meant to be a Q&A question. I've already found a solution and I want to share with others.
I recently ran into an issue where android studio would complain that Program type already present: androidx.exifinterface.R. This happened after adding the implementation 'com.google.android.play:core:1.6.4' dependency. I had stumbled on this before with androidx.asynclayoutinflater.R. I've found the that adding something like the following to your module level gradle file will fix it:
configurations.all {
// This is from a previous, similar issue
exclude group: "androidx.asynclayoutinflater", module: "asynclayoutinflater"
// This is the LOC that fixed the issue in this post
exclude group: "androidx.exifinterface", module: "exifinterface"
}
The pattern seems to be:
if there's a complaint about androidx.MODULE_X.R already being present
then add
exclude group: "androidx.MODULE_X", module: "MODULE_X"
to configurations.all in module level gradle file
This worked for both asynclayoutinflater and now exifinterface. I don't know if the pattern scales but so far it has worked. My understanding of the underlying issue is that two dependencies in the module dependency graph (eg com.google.android.play:core) explicitly include the problematic module (eg exifinterface) and so we need to exlude one of those explicit dependencies. My understanding might be wrong.
The gradle docs don't take the time to explain the entities they are dealing with. That's why I want to ask such a basic question.
I've got a to understand in detail, what the terms group, module and artifact really mean to alter this code:
compile('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
About a year ago I used that exclude statement I took from Android dalvik conversion for xmlpullparser to fix a Multiple dex files failure.
However, after upgrading to Android Studio 3.0 that error occurrs again! Now it says: Multiple dex files define Lorg/xmlpull/mxp1/MXParser and sometimes ...XmlPullParserException.java So, id like to understand how the parameters I give exclude must be shaped.
Reading the documentation one could think a group is the package name and the artifact is the class:
//excluding a particular transitive dependency:
exclude module: 'cglib' //by artifact name
exclude group: 'org.jmock' //by group
exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
Another chinese page (translated) used those excludes
compile ( 'com.thoughtworks.xstream: xstream: 1.4.7' ) {
exclude group : 'xmlpull'
exclude group : 'XmlPullParser'
}
Built on that findings wonder
how xmlpull worked when the package name begins with org.xmlpull?
what projects those terms refer to in my scenario. Where was the group name defined?
What kinda group is XmlPullParser?
Must I clean, rebuild or just build the project after altering those parameters? Because sometimes it complains about different files.
The group, artifact and version are chosen semi randomly and do NOT need to match packages or classes in the jar file.
For example commons-lang has groupId = 'commons-lang' but the classes are in org.apache.commons.lang.* package
The group, artifact and version are defined within the build file of the project. In maven this will be in pom.xml in gradle this will be in build.gradle (and settings.gradle)
If you want to know the group, artifact, version for a project (aka GAV, aka maven co-ordinates) you will usually go to the project's home page.
You can also use the maven central advanced search to "fuzzy" search eg by artifactId or by a classname within a jar. If you are using an in-house repository you can likely "fuzzy" search via the web interface there also
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.
When I was trying to use Android Studio to debug my project, I got the following error,
Class com.google.ads.AdRequest.Gender has already been added to output. Please remove duplicate copies.
The cause seems to be that the google play services lib and another lib used by my project both contain the com.google.ads.AdRequest.Gender class, and I don't think I can remove it from either one.
Does anyone know how to fix this problem?
Thanks a lot.
I tried the following statement in build.gradle in order to exclude the duplicated classes in the google play services lib, but it still does not solve the problem.
compile ('com.google.android.gms:play-services:4.1.32') {
exclude group: 'com.google.ads'
}
You can try using Gradle's exclude mechanism when setting up the DatawindAdsSdk-2.0 dependency. There are docs available, but it will probably look something like this:
dependencies {
compile files('libs/datawindAdsSdk-2.0.jar') {
exclude group: 'com.google.ads'
}
}
experiment with that and see if you can get it working.
But I came to this post via google and I read this post has the same problem as me. I solved it excluding the group and the whole library. In my case the problem was with an animatorListener.
compile ('com.rengwuxian.materialedittext:library:1.8.2'){
exclude group: 'com.nineoldandroids', module: 'library'
}
This is my post duplicate library gradle animatorlistener duplicate