Duplicate class contained in the libs of android project - android

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

Related

Program type already present androidx.exifinterface.R

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.

Error: Program type already present when building project

I'm using an 'aar' library which I created.
In both, my project and the library, there is a dependency implementation of Conceal library (each from its own lib folder).
When I build the project after importing the library and using ProGuard obfuscation, I get this error message:
Error: Program type already present: com.facebook.crypto.cipher.NativeGCMCipher
How can I resolve this problem?
this error say you are importing the dependency which already imported in project.
solution :- remove or exclude this dependency
ex:-
compile ('com.github.ganfra:material-spinner:1.1.1'){
exclude group: 'com.nineoldandroids'
}
according to mavenCentral(), this is the package name (which could be used instead of .jar):
// https://mvnrepository.com/artifact/com.facebook.conceal/conceal
implementation "com.facebook.conceal:conceal:2.0.2"
therefore the exclusion should look about like this:
implementation( project(":libraryproject") ) {
exclude group: "com.facebook.conceal"
}
To my understanding, the error means that I imported a dependency that already imported in the project (once in the project and once in the library).
The suggested solutions of #Mayur Dabhi and #Martin Zeitler had the right approach, but unfortunately, I wasn't able to get the exclude command working.
finally, with the help of #Martin Zeitler, I replaced:
implementation files('libs/conceal_android.jar')
implementation files('libs/libconceal.jar')
with:
implementation "com.facebook.conceal:conceal:2.0.2"
meaning I removed the 'Conceal' jar files from the 'lib' folder and imported the dependency. After that, the error message disappeared and I managed to build the project.
Thanks for anyone who tried to help :)

Can´t exclude duplicated library dependencies in build.gradle

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.

How to troubleshoot duplicate entry duplicate entry: javax/annotation/ParametersAreNullableByDefault.class

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?

Android Studio: Duplicate files copied in APK META-INF/DEPENDENCIES when compile

I exported my project from Eclipse and imported to Android Studio using the instructions in this link: http://developer.android.com/sdk/installing/migrate.html
When I build, I have an error:
Duplicate files copied in APK META-INF/DEPENDENCIES
After searching, I found a solution: add
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
into build.gradle. And it works!
But I don't understand why I had this error and why I've had to apply that fix. Can anybody explain?
While Scott Barta's answer is correct, is lacks a simple and common solution: just add
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
to your build.gradle to ignore those duplicates.
In Android Gradle builds, you're not permitted to include the same file with the same path more than once in the output. In your build, there were two META-INF/DEPENDENCIES files coming from different places. Since you don't need this file at all in your application, the simplest thing to do is to tell the build system to ignore it altogether, which is what this exclude directive does.
There's also a pickFirst directive to tell the build system to keep one of the copies; there's a tiny amount of detail on that in Android Gradle plugin 0.7.0: "duplicate files during packaging of APK".
Android builds in Gradle are rather strict about duplicate files, which can make life difficult. There's a similar problem if you include the same Java class more than once, where you get the "Multiple dex files define" error (see Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat) for a typical example).
Other build systems are more lenient. It's typical in Java that if you include the same class more than once in a classpath, for example, the first copy it sees is the one that's used; duplicates after that are ignored. This is in most cases easier to deal with, but it has a couple problems. The biggest one is that there can be subtle errors if multiple different versions of a file creep into the build without you knowing -- it can be difficult to figure out what's going on. When you do figure it out, you can usually solve it by juggling the order in which things are included to make sure the one you want makes it to the final output, but in very complex builds, this can be difficult to achieve, and it can happen that doing seemingly unrelated things like including new libraries in your project can upset the ordering and lead to a lot of woe.
For that reason, Gradle has the philosophy of not relying on ordering of things to determine "winners" in the game of resolving duplicates, and it forces the developer to make all dependencies explicit. Android's implementation of its build system on top of Gradle follows that philosophy.
The simplest solution is to add
packagingOptions {
pickFirst 'META-INF/*'
}
to your build.gradle in android section
The easiest way I've found to resolve this problem is to use a wildcard, so you don't find yourself having to manually declare each file in conflict.
packagingOptions {
pickFirst '**'
}
In case that anyone having these problem while uploading new .apk to Google Play Store, after updatng Android Studio ;
click V1 Jar Signature not Full Apk Signature while Generating new Apk with old Keystore
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-ads:10.2.1'
implementation 'com.android.support:support-annotations:25.0.1'
testImplementation 'junit:junit:4.12'
**// select only one in two line below** implementation ‘package’ //implementation project(‘:package’)
}
// good luck

Categories

Resources