androidandroid-studiokotlingradleandroid-graphview

How to use graphview with graphview library


I am trying to create a graph with the graphview library and create a simple graph

When I included the dependency in my build.gradle, I got an error that I can't solve.

build.gradle (.app)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}


android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.lightrdetect"
        minSdk 23
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

}

configurations {
    ktlint
}

dependencies {

    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation "org.jetbrains.anko:anko-sdk21:$anko_version"
    implementation 'com.jakewharton.timber:timber:4.7.1'
    implementation 'com.airbnb.android:lottie:3.4.0'
    implementation 'com.jjoe64:graphview:4.2.2'

    ktlint "com.pinterest:ktlint:0.36.0"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'



}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    classpath = configurations.ktlint
    main = "com.pinterest.ktlint.Main"
    args "src/**/*.kt"
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Fix Kotlin code style deviations."
    classpath = configurations.ktlint
    main = "com.pinterest.ktlint.Main"
    args "-F", "src/**/*.kt"
}

gradle.properties

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
android.enableJetfier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true

settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        jcenter()
        mavenCentral()
        maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
    }
}
rootProject.name = "LIGHTR DETECT"
include ':app'

the error i have:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)


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

Before including the implementation 'com.jjoe64:graphview:4.2.2' and trying to create a simple graph, my application was working fine.

Do you have a solution ?

Best regard. P.Congré


Solution

  • add

    packagingOptions {
        resources {
            excludes += [
                    '/META-INF/{AL2.0,LGPL2.1}',
                    'META-INF/DEPENDENCIES',
                    'META-INF/LICENSE',
                    'META-INF/LICENSE.txt',
                    'META-INF/license.txt',
                    'META-INF/NOTICE',
                    'META-INF/NOTICE.txt',
                    'META-INF/notice.txt',
                    'META-INF/ASL2.0',
                    'META-INF/*.kotlin_module'
            ]
        }
    }
    

    in your build.gradle file and in android block