Paul
Paul

Reputation: 69

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?

Upvotes: 3

Views: 6641

Answers (4)

YuvrajsinhJadeja
YuvrajsinhJadeja

Reputation: 1422

Go to gradle.properties and write these two lines of code:

android.useAndroidX=true # may be set already
android.enableJetifier=true

Upvotes: 1

jay patoliya
jay patoliya

Reputation: 761

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)

Upvotes: 1

Paul
Paul

Reputation: 69

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.

Upvotes: 1

Bach Vu
Bach Vu

Reputation: 2348

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

Upvotes: 2

Related Questions