如何在模块的 build.gradle 中而不是在顶层(项目的)build.gradle 中使用存储库?

hua*_*iao 3 android gradle build.gradle android-gradle-plugin

例如,当我使用“activeandroid”时,我必须走两步:

1) 在我的项目的 build.gradle(Top-level build.gradle) 中,添加

repositories {
    jcenter()
    // ActiveAndroid
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
Run Code Online (Sandbox Code Playgroud)

2) 在我模块的 build.gradle 中,添加

compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
Run Code Online (Sandbox Code Playgroud)

但是我可以在模块的 build.gradle 中添加存储库吗?顺便说一句,当我这样做时,我遇到了很多错误,无法成功构建。

小智 11

在包含根项目子句后,这对我有用。

rootProject.allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
}

dependencies {
    compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
}
Run Code Online (Sandbox Code Playgroud)