Pra*_*ath 6 java android maven android-studio
我想在android studio项目中使用maven库。在库文档中,他们提到这样添加,
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
Run Code Online (Sandbox Code Playgroud)
但在新的 android studiobuild.gradle文件中看起来像这样
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
}
Run Code Online (Sandbox Code Playgroud)
那么,我要如何添加这个库存储库,谢谢
在最新的Android Studio Bumblebee(2021.1.1)版本中,如果你在新的结构中看到它build.gradle(Project)看起来像这样
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
}
Run Code Online (Sandbox Code Playgroud)
为了使用其他库,例如maven,您必须访问 ,settings.gradle并且必须访问 Maven 链接,如下所示
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'
Run Code Online (Sandbox Code Playgroud)
最后将库添加到您的
Build.gradle(module)
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
Run Code Online (Sandbox Code Playgroud)
参考Prasath 的回答,我会简化答案。在旧的 gradle 结构中,Project build.gradle 中有一行:
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // this is your line
}
Run Code Online (Sandbox Code Playgroud)
在新的 gradle 结构中,您必须在 settings.gradle 中添加一行,如下所示:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // // this is your line
}
}
Run Code Online (Sandbox Code Playgroud)
您不必在settings.gradle 的pluginManagement{} 部分添加该行。
小智 5
如果你想将maven url添加到settings.gradle.kt文件中添加如下:
maven {url = uri("https://www.jitpack.io" ) }
10 月 3 日,这条线路对我有用。2023年
| 归档时间: |
|
| 查看次数: |
7606 次 |
| 最近记录: |