Duplicate class * found in modules (Android, gradle) - android

My gradle.properties file contains this:
android.useAndroidX=true
android.enableJetifier=true
Below is my gradle file code:
packagingOptions {
exclude "**/attach_hotspot_windows.dll"
exclude "META-INF/licenses/**"
exclude "META-INF/AL2.0"
exclude "META-INF/LGPL2.1"
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
//Adyen
implementation "com.adyen.checkout:3ds2:4.7.1"
implementation "com.adyen.checkout:card-ui:3.8.3"
implementation "com.adyen.checkout:redirect:4.7.1"
//Firebase imports
implementation 'com.google.firebase:firebase-crashlytics:18.2.7'
implementation 'com.google.firebase:firebase-analytics:20.0.2'
implementation 'com.google.firebase:firebase-messaging:23.0.6'
//UI imports
etc. imports
}
When I added //Adyen imports I started to get error message like this:
Duplicate class com.adyen.checkout.core.BuildConfig found in modules jetified-checkout-core-4.7.1-runtime (com.adyen.checkout:checkout-core:4.7.1) and jetified-core-v3-3.8.3-runtime (com.adyen.checkout:core-v3:3.8.3)
Duplicate class com.adyen.checkout.core.api.BaseHttpUrlConnectionFactory found in modules jetified-checkout-core-4.7.1-runtime (com.adyen.checkout:checkout-core:4.7.1) and jetified-core-v3-3.8.3-runtime (com.adyen.checkout:core-v3:3.8.3)
Duplicate class com.adyen.checkout.core.api.Connection found in modules jetified-checkout-core-4.7.1-runtime (com.adyen.checkout:checkout-core:4.7.1) and jetified-core-v3-3.8.3-runtime (com.adyen.checkout:core-v3:3.8.3)

android {
applicationVariants.all { variant ->
variant.getRuntimeConfiguration().exclude group: 'com.adyen.checkout:checkout-core:4.7.1', module: 'your-module'
}
}

Related

Duplicate class using product flavours

My android gradle build has many flavours.
One of then has an aar file that contains a duplicate dependency (com.google.zxing).
build.gradle:
...
dependencies {
implementation 'com.google.zxing:core:3.3.3'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
// Standard flavour
standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
exclude group: 'com.google.zxing', module: 'android-core'
transitive = false
}
...
}
This configuration produces the following for "standard" build (works for another flavours):
Duplicate class com.google.zxing.BarcodeFormat found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.Binarizer found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.BinaryBitmap found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.ChecksumException found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos8
...
I tried to change the config to:
standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
configurations {
all*.exclude group: 'com.google.zxing'
}
}
The config above works only when i'm build the "standard" flavour. To another flavors, this error occurs:
error: package com.google.zxing.qrcode.decoder does not exist
What i'm doing wrong?
Solution:
{
configurations {
exclude group: 'com.google.zxing'
}
}
use exclude instead all*exclude

Duplicate jar entry-android

I added 3rd party .aar file to my app. its runs smoothly without any issue. But when going to create APK file i get duplicate entry error
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForQaRelease'.
> java.io.IOException: Can't write [/Volumes/***/**/PROJECT/app/build/intermediates/transforms/proguard/qa/release/0.jar] (Can't read [/Users/ayeshdon/.gradle/caches/transforms-2/files-2.1/934a6f302e2712d6028d37a9dc4ccd20/jars/libs/commons-lang3-3.3.2.jar(;;;;;;;**.class)] (Duplicate jar entry [org/apache/commons/lang3/AnnotationUtils$1.class]))
My Gradle file is like this:
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation (project(":LIBRARYNAME"))
What is wrong here?
Whatever that "3rd party .aar file" may be, it complains about some Duplicate jar entry [org/apache/commons/lang3/AnnotationUtils$1.class]; therefore it's either:
implementation (project(":LIBRARYNAME")) {
exclude group: "org.apache.commons", module: "commons-lang3"
}
Or:
implementation fileTree(dir: "libs", include: ["*.aar", "*.jar"]) {
exclude group: "org.apache.commons", module: "commons-lang3"
}

How to exclude certain part of a gradle dependecy?

Multiple dependencies has similar named class and I'm getting duplicate class errors. To solve I think excluding those parts may help. How to exclude these parts?
Errors +lots of similar lines:
Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Dependencies:
// gRPC
implementation "io.grpc:grpc-okhttp:$grpcVersion"
implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
implementation 'javax.annotation:javax.annotation-api:1.3.2'
//protobuf 'com.google.protobuf:protobuf-java:3.8.0'//error persist with this and without this
// OAuth2 for Google API
implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
//Translation
implementation "com.google.cloud:google-cloud-translate:$grpcVersion"
implementation('com.google.cloud:google-cloud-translate:1.79.0') {
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.json', module: 'json'
//I want to exclude error classes here...HOW?...
//exclude group: 'com.google.protobuf', module: 'protobuf-java-3.7.1'
}
annotationProcessor "com.google.cloud:google-cloud-translate:$grpcVersion"
grpc version on ext:
grpcVersion = '1.4.0'
these are not related to support library versions as these are because of translation and protobuf-lite libraries. these are using different versions of those class and I dont know if excluding of them will work or not.
Is it possible to extract those libraries and change those class names?
I want to see if excluding those classes can solve it. How to exclude?

Build errors. Duplicate class android.support.v4

I have created a simple image to text app using Visual Studio following uTube guide https://www.youtube.com/watch?v=CLjzLiU_GpE
I am new to app dev and wanted to learn this but cant get to compile.
I have tried to follow similar errors in here
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes?
When I try to follow this and add to the AndroidStudioProjects\ImageToTextApp\gradle.properties
I get more errors
My errors are as show but i have included (only) first and last 2, there are 390 in total.
I think i can see it tells me (as per other issues in here) that the class is in 2 libraries.
(com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Were do i see my project importing these libraries and how do I fix these errors.
Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
...
Duplicate class android.support.v4.widget.ViewDragHelper$2 found in modules classes.jar (com.android.support:customview:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.widget.ViewDragHelper$Callback found in modules classes.jar (com.android.support:customview:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Go to the documentation to learn how to Fix dependency resolution errors.
Hi #BachVu
I added your suggested line and the build.gradle file now looks like
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0' implementation
'com.android.support.constraint:constraint-layout:2.0.0-beta1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-vision:10.2.4'
exclude module: 'support-v4' }
But this just creates more errors
ERROR: Gradle DSL method not found: 'exclude()'
Do i need to add another import or have i added in the wrong place?
Try adding this line to the library that causes this issue exclude module: 'support-v4' like this:
implementation("androidx.recyclerview:recyclerview:x.x") {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
}
Here is my build.Gradle file now and all works fine;
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-vision:17.0.2' }
The main difference is
com.google.android.gms:play-services-vision:10.2.4
For some reason this was okay then out of nowhere it advised it was out of date. Once I updated from 10.2.4 > 17.0.2 all the errors went away.
Thanks for your time.
Try to migrate AndroidX
==> Step 1
Just go to
Refactor > Migrate to AndroidX > Migrate > Do Refactor
==> Step 2
Update your classPath and all dependencies with the latest version(Alt+Enter)
Go to gradle.properties and write these two lines of code:
android.useAndroidX=true # may be set already
android.enableJetifier=true

Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback

I completely new to Android Development and can't seem to resolve this error:
"Error: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback"
This is my dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
implementation "android.arch.navigation:navigation-fragment:1.0.0-alpha01"
implementation "android.arch.navigation:navigation-ui:1.0.0-alpha01"
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
testImplementation 'junit:junit:4.12'
}
I've googled some and ended up on the developer page about "Resolve duplicate class errors", but I'm still not able to fix this. Help would be very much appriciated!
Option 1
Following worked for me
Add the following in your gradle.properties file
android.useAndroidX = true
android.enableJetifier = false
Option 2 (if above does't work)
Android studio -> Navigate -> Class
Check include non-project classes
Copy full class path android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
See where it is used. You may need to remove, one of them.
Option 3
you might be including package which is including modules as well so exclude the support-v4 module with following method
implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
exclude group: 'com.android.support', module:'support-v4'
}
You can analyze the conflicting modules using ./gradlew :YOURPROJECT:dependencies from a command line in your project repository.
Check especially your third party libraries for occurences of "com.android.support-":
Then exclude the conflicting modules from these dependencies like:
implementation ("com.jakewharton:butterknife:8.8.1") {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotation'
exclude group: 'com.android.support', module: 'support-compat'
}
Im using flutter, and Im adding some native libraries in android, I tried the solutions posted here, but the trick for me was android.enableJetifier = true instead false
So, adding the following code to the gradle.properties, my apps are running:
android.useAndroidX = true
android.enableJetifier = true
if you still getting error after
# gradle.properties
android.useAndroidX = true
android.enableJetifier = false
then you probably forgot about main activity that calling android.support.v7.app.AppCompatActivity
change it to androidx.appcompat.app.AppCompatActivity
adding following plugins
cordova plugin add cordova-plugin-androidx
cordova plugin add cordova-plugin-androidx-adapter
solved the problem for me
At least for me the issue was with the implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' dependency. I went into the menu in Android Studio to create a Blank Fragment in Kotlin just to see what that would look like and the dependency above was added.
Once i removed that dependency the error went away.
Some of your existing dependencies are using older versions of support library, try this
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' {
exclude group: 'com.android.support'
exclude module: 'support-v4'
}

Categories

Resources