【问题标题】:how to add a project level dependency in gradle如何在 gradle 中添加项目级别的依赖项
【发布时间】:2016-03-18 20:47:22
【问题描述】:

我的应用程序中有一个应用程序和一个 android 库,在开发环境中我想提供一个项目级别的依赖项,即在 (项目:XXX)build.gradle 文件。 这就是我的项目级 build.gradle 的外观(部分视图)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        compile 'io.reactivex:rxandroid:1.1.0'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
        compile 'io.reactivex:rxjava:1.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

我收到一个错误Gradle DSL method not found : compile()

android 有没有办法提供通用的项目级依赖。

【问题讨论】:

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


    【解决方案1】:

    您不能将依赖项添加到除 buildscript 块中的 classpath 之外的任何其他范围。 以下是您声明项目依赖项的方式(在另一个项目中,而不是在 buildscript 中):

    dependencies {
            compile project(':shared')
        }
    

    【讨论】:

      【解决方案2】:

      您正在使用buildscript 内的dependencies 块。错了。

      buildscript {
          repositories {
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:1.5.0'
          }
      }
      
      
      
      dependencies {
           compile 'io.reactivex:rxandroid:1.1.0'
           compile 'io.reactivex:rxjava:1.1.0'        
      }
      

      【讨论】:

        猜你喜欢
        • 2023-02-06
        • 2014-09-21
        • 1970-01-01
        • 2015-03-17
        • 2016-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多