skip to Main Content

I want to use the maven library in the android studio project. in the library documentation, they mention adding like this,

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

dependencies {
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
} 

But in the new android studio build.gradle file looks like this

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

So, how do I want to add this library repository, Thank you

3

Answers


  1. Chosen as BEST ANSWER

    In the latest Android Studio Bumblebee(2021.1.1) version, if you see it in build.gradle(Project) the new structure looks like this

    build.gradle(Project)

    plugins {
        id 'com.android.application' version '7.1.0' apply false
        id 'com.android.library' version '7.1.0' apply false
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    In order to use the other libraries like maven, you have to go to the settings.gradle and you have to the maven link like below

    settings.gradle

    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
            mavenCentral()
            maven { url 'https://jitpack.io' } // add like this
        }
    }
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
            maven { url 'https://jitpack.io' } // add like this
        }
    }
    rootProject.name = "your project name here"
    include ':app'
    

    setting.gradle

    finally add the library in to your Build.gradle(module)

    dependencies {
        implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    }
    

  2. I recently had a lot of confusion with this, but I was able to solve it this way, I just added Maven in Settings.graddle, when I added twice this caused me conflicts, but when I tried just adding once then it worked correctly.

    I am using Android Studio Dolphin 2021.3.1.

    how to add Maven Jitpack.io on Android 2022

    Login or Signup to reply.
  3. Referring to answer from Prasath, I would simplify the answer.
    In old gradle structure you have a line in Project build.gradle:

    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' } // this is your line
    }
    

    In new gradle structure you have to add a line in setting.gradle like this:

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
            maven { url 'https://jitpack.io' } //  // this is your line
        }
    }
    

    You do not have to add the line in pluginManagement{} section in settings.gradle.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search