【问题标题】:How can I use repositories in my module's build.gradle not in Top-level(Project's) build.gradle?如何在我的模块的 build.gradle 中使用存储库而不是在顶级(项目的)build.gradle 中?
【发布时间】:2023-03-17 06:18:01
【问题描述】:

例如,当我使用'activeandroid'时,我必须进行两个步骤:

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

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

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

compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'

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

【问题讨论】:

    标签: android gradle android-gradle-plugin build.gradle


    【解决方案1】:

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

    rootProject.allprojects {
        repositories {
            jcenter()
            mavenCentral()
            maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        }
    }
    
    dependencies {
        compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
    }
    

    【讨论】:

      【解决方案2】:

      是的,你可以做到。

      apply plugin: 'com.android.application'
      
      repositories {
          jcenter()
          mavenCentral()
          maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
      }
      
      dependencies {
          compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT' 
      }
      

      不要将repositories 块与buildscript 块内的存储库混淆。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-02
        • 2023-03-26
        • 1970-01-01
        • 1970-01-01
        • 2014-11-10
        • 2015-03-21
        • 2015-11-13
        • 2013-06-18
        相关资源
        最近更新 更多