Build errors. Duplicate class android.support.v4 - android

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

Related

Duplicate class * found in modules (Android, gradle)

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'
}
}

Resolve duplicate classes with firebase and dialog-flow

I am working on a mobile app where I need dialog-flow in order to get some information from a user message. The problem is, when I implement dialog-flow into the app gradle, I get an error on build, saying that I have multiple duplicate classes ( conflicting with firebase classes).
I've tried methods suggested here:
https://stackoverflow.com/a/51695425/11023871
and even searched on the github repository of dialog-flow:
https://github.com/googleapis/google-cloud-java/issues/5608#issue-462434090
I tried to exclude 'google-protobuf', but that didn't help (I got compilation error on dialog-flow components).
I attached my dependencies below.
dependencies {
implementation 'com.hbb20:ccp:2.2.4'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-firestore:19.0.2'
implementation 'com.google.cloud:google-cloud-dialogflow:0.99.0-alpha'
}
EDIT
These are some of the duplicates specified by gradle:
Duplicate class com.google.api.Advice found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)
Duplicate class com.google.api.Advice$1 found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)
Duplicate class com.google.api.Advice$Builder found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)
Duplicate class com.google.api.AdviceOrBuilder found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)
Duplicate class com.google.api.AnnotationsProto found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)
Duplicate class com.google.api.AuthProto found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)
I was stuck with the same issue and after months of debugging and thanks to an update from Google and Firebase, I came by a solution that's working.
I needed to change library versions of Firebase and dialog flow.
Change min SDK version to 19 if lesser than 19 in your project.
Firebase implementation:
Dialog flow implementation:
Add the following snippet to your build.gradle and then run gradle findDuplicates. This will list any duplicate classes and which jars they are in. After that you can see which ones you want to exclude.
task findDuplicates {
doLast {
Map<String, List<File>> pathMap = [:]
configurations.runtime.each { file ->
FileTree tree = file.directory ? fileTree(file) : zipTree(file)
tree.visit { FileVisitDetails fvd ->
if (!fvd.directory) {
String path = fvd.path
List<File> fileList = pathMap[path]?:[]
fileList << fvd.file
pathMap[path] = fileList
}
}
}
pathMap.each { path, fileList ->
if (fileList.size() > 1) {
println "Found duplicate $path in $fileList"
}
}
}
}
I have the duplicate classes and it's jars, but I never excluded something from gradle. Could you please help me out? For example, I have this: "Duplicate class com.google.api.Advice found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)"
I'm not sure why these jars are duplicating the same classes or which one you want to keep. But you can do something like
dependencies {
implementation 'com.hbb20:ccp:2.2.4'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
...
}
configurations.implementation.exclude(group: 'com.google.firebase', module: 'protolite-well-known-types')

Why I'm Getting Duplicate Class When Running My Android Project

I'm in the process of adding a navigation drawer to my app. and I'm getting errors. The app gradle synchs just fine. but when I run the app I get a bunch of duplicate class error. I think it might be because I have conflicting dependencies added and that I'm using v7 28.0.0 and some of the errors mention app: v4. all the examples I've seen online use v7 28.0.0 eventhough I have this in main_activity.xml which uses v4. don't know if it's got something to do with the error. android.support.v4.widget.DrawerLayout
Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: 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.app.ActionBarDrawerToggle$Delegate 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.app.ActionBarDrawerToggle$DelegateProvider 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.app.ActionBarDrawerToggle$SlideDrawable 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.app.ActivityCompat 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.ActivityCompat$1 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.ActivityCompat$OnRequestPermissionsResultCallback found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.pctechtips.netdroid"
minSdkVersion 21
targetSdkVersion 28
versionCode 8
versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = false
signingConfig signingConfigs.config
}
buildTypes {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
/*androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
firebase
implementation 'com.google.firebase:firebase-core:10.2.1'
})*/
// compile 'com.android.support:appcompat-v7:25.3.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
/*google play plugin for adMob*/
implementation 'com.google.android.gms:play-services:10.2.1'
implementation 'commons-net:commons-net:3.6'
implementation 'org.samba.jcifs:jcifs:1.3.3'
}
The exception means, There were duplicated classes in 2 or more different dependencies and the compiler wouldn't be able to distinguish which of them should be used at run-time and the exception was thrown.
Most often, Duplicity happens when you are trying to import modules that carrying their required libraries. (transitive dependencies)
You have to exclude duplicated classes from libraries in the build.gradle.
As Log shows, support-core-ui and support-compat modules have duplicated classes.
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all { // You should exclude one of them not both of them
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-compat"
}
}
}
Sometimes you don't need to exclude anything and you only need to change the imported module to that one that does not bring its dependencies.
Other situation that causes duplicated classes is when you have added *.jar to the project libs directory. Therefore, You need to delete them if they are not begin used in the project.
project->app->libs->*.jar
I see there are some solutions mentioned using these 2 lines will resolve the problem But if you've migrated to Androidx it would be enabled by default.
android.useAndroidX=true
android.enableJetifier=true
Jetifier is
Jetifier tool migrates support-library-dependent libraries to rely on
the equivalent AndroidX packages instead. The tool lets you migrate an
individual library directly, instead of using the Android gradle
plugin bundled with Android Studio.
And for more information take a look at Exclude transitive dependencies
As an app grows in scope, it can contain a number of dependencies
including direct dependencies and transitive dependencies (libraries
which your app's imported libraries depend on). To exclude transitive
dependencies that you no longer need, you can use the exclude
keyword
If you have problems excluding classes, check this thread: How do I exclude...
See if adding this dependency works:
implementation 'com.android.support:support-v4:28.0.0'
Go to gradle.properties and write these two lines of code:
android.useAndroidX=true
android.enableJetifier=true
Please update com.google.android.gms:play-services to latest version. it wil work.
I tried all above solution, but nothing worked in my case. What worked for me is.
I got this problem resolved by creating a new project with the same project and package name and then copying files from the previous project to new one.

com.android.builder.merge.DuplicateRelativeFileException

When I implement these two dependencies in my project:
For BTC implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
For BCH implementation 'cash.bitcoinj:bitcoincashj-examples:0.14.5.2'
This error will occur:
Caused by: com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'org.bitcoin.production.checkpoints.txt'
How can I resolve this?
This issue appears because bitcoincashj-examples library also transit org.bitcoinj:bitcoinj-core:0.14.5.2 dependency.
All that you need to do is exclude org.bitcoinj:bitcoinj-core:0.14.5.2 dependency from bitcoincashj-examples library.
implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
implementation ('cash.bitcoinj:bitcoincashj-examples:0.14.5.2'){
exclude group: 'cash.bitcoinj', module: 'bitcoinj-core'
}

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