javaandroidmavenbuild.gradlempandroidchart

Can't import MPAndroidChart libraries into Activity declaring in TOML and build.gradle (app)


I'm in Sdk 35. I've declared MPAndroidChart in my Android project:

That works. But now i can't import libraries in my Activity (using Java) like

import com.github.mikephil.charting.charts.LineChart;

import com.github.mikephil.charting.charts.BarChart;

I've tried this inside dependencyResolutionManagement: maven { url 'https://jitpack.io' } in my settings.gradle.kts, but it doesn't accept that ("Unexpected tokens (use ';' to separate expressions on the same line") nor that maven { url (https://jitpack.io) }

I've tried to look for help, but everyone says I need this maven { url 'https://jitpack.io' } and it doesn't compile at all.

Edit: ok, now i've seen this warning also in my project,but everybody answer this problem with maven { url 'https://jitpack.io' } and it doesn't seems to be working.

Okey, i've seen this one. It seems to work for now.

settings.gradle.kts=

    repositories {
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven{
            url = uri("https://jitpack.io")
        }
    }
}

rootProject.name = "projectname"
include(":app")

Solution

  • settings.gradle and settings.gradle.kts have the same role but have different syntax. settings.gradle is in Groovy, while settings.gradle.kts is in Kotlin.

    Groovy supports a wide range of string notation, whereas Kotlin sticks mostly to C/Java-style double-quotes. Plus, Groovy is not as stringent about data types and supports somewhat ad hoc syntax for function parameters and variable assignments, while Kotlin is more strict.

    So, if you see instructions like this for settings.gradle:

    maven { url 'https://jitpack.io' }
    

    ...you need to translate it to Kotlin for settings.gradle.kts:

    maven { url = uri("https://jitpack.io") }
    

    Here: