简体   繁体   中英

How to add Repository maven in new Android Studio Project setup(2022)?

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

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'

设置.gradle

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

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

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.

如何在 Android 2022 上添加 Maven Jitpack.io

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM