0

So I've been trying to use GraphView. I've imported it into my dependencies but for some reason I get a dependency resolution error. Here is my app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.getbase:floatingactionbutton:1.10.1'
    implementation 'org.jetbrains:annotations-java5:15.0'
    implementation 'com.jjoe64:graphview:4.2.2'
}

But When I try to run the app, the build fail and I get the following error:

"Duplicate class com.jjoe64.graphview.GraphView found in modules GraphView-3.0.jar (GraphView-3.0.jar) and classes.jar (com.jjoe64:graphview:4.2.2)
Duplicate class com.jjoe64.graphview.GraphView$1 found in modules GraphView-3.0.jar (GraphView-3.0.jar) and classes.jar (com.jjoe64:graphview:4.2.2)

Go to the documentation to learn how to Fix dependency resolution errors."

And the line "implementation 'com.android.support:appcompat-v7:28.0.0'" shows error, and claims that I'm using both version 28.0.0 and 27.1.1.

What am I missing?

  • That basically mean that libraries have the same methods and compiler can't choose which one are needed. Do you use all the last versions of libraries? – Blind Kai Aug 09 '19 at 20:49

3 Answers3

1

The problem probably could occur because of that both libraries use the same class. In this case it's GraphView-3.0.jar. The compiler can't choose which one is needed to be used. So you could remove this .jar in one of the libraries and then try to use it.

Otherwise, you could just use the version of support library appcompat-v7:27.1.1 and then both libraries would use the same version and there won't be any conflict.

The similar problem and possible solution are described here: link

Blind Kai
  • 514
  • 5
  • 14
1

It seems you've updated the library version. For graphview from 3.0 to 4.2.2. Same with appcompat. But gradle could not delete the old library for some reason. So it's trying to add both of the library to the classpath.

Try to clean and build the project. If not working, clear gradle cache and rebuild. If still not working, find the old jar manually and delete.

Shaiful
  • 5,643
  • 5
  • 38
  • 41
1

You can add below lines into your gradle.properties file:(Don't repeat if its there)

android.useAndroidX=true android.enableJetifier=true

Source: https://github.com/jjoe64/GraphView/issues/677

Fendy
  • 11
  • 1