我想使用 Stepper-Touch github 库。为此我必须添加 jitpack.io
allproject{
repositories{
[here]
}
}
在我的 build.gradle 项目文件中。没有
allproject{...}
部分,所以我自己添加了它,但我得到了这个错误
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
然后我寻找答案,发现有人说我应该删除
dependencyResolutionManagement
我的 settings.gradle 文件中的 部分。我这样做了,但其他依赖项(例如约束布局、实时数据的依赖项)停止工作。 帮帮我,我该如何解决这一切? :(
从 7.X.X gradle 构建工具开始。 allprojects 已弃用,使用 dependencyResolutionManagement 是在构建的每个子项目中声明存储库的最佳实践。因此,Android 项目将不再在其项目 build.gradle 文件中生成 allprojects 块。相反,它将在 settings.gradle 中生成一个 dependencyResolutionManagement 块。
如果您使用 dependencyResolutionManagement 来实现与 allprojects 块相同的结果,您不应该遇到任何问题。您可以将存储库添加到 dependencyResolutionManagement 存储库块,就像使用 allprojects 块一样
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// e.g this is how you would add jitpack
maven {
url = uri("https://jitpack.io")
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// e.g this is how you would add jitpack
maven { url "https://jitpack.io" }
// Add any repositories you would be adding to all projects here
}
}
我在下面列出了旧方法,但这可能不适用于 Android Gradle 插件 4.0 或更高版本
从 settings.gradle 中删除整个 dependencyResolutionManagement 块,使其看起来像
rootProject.name = "My Application"
include ':app'
然后将 allproject 块添加到项目 build.gradle 中,并确保添加 dependencyResolutionManagement 中的所有依赖项,因此在我们的示例中它看起来像这样
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
// e.g this is how you would add jitpack
maven { url "https://jitpack.io" }
// Add any repositories you would be adding to all projects here
}
}