我在哪里添加我的依赖项? build.gradle 放哪?

Where do i add my dependencies? In which build.gradle to put them?

我被要求添加一些依赖项。我知道它们应该添加到 build.gradle,但在依赖项部分写着:

dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

我是 android 的新手,所以根据我的小经验和谷歌搜索应该有两个 build.gradle 文件,只有其中一个我应该添加依赖项,但我找不到一个额外的 build.gradle 文件!?

我很乐意为您提供帮助!我应该在哪里添加我的依赖项,我的第二个 build.gradle 在哪里消失了?

Gradle 是一个有点奇怪的工具。 https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html

他们在这里说明它是如何工作的。每个项目只有一个 build.gradle 可以为您提取和管理依赖项。

Android Studio 对此进行了扩展。整个项目有一个 'main' build.gradle,然后每个子模块都有一个 build.gradle,因为它们是 运行 作为单独的程序。在主项目 build.gradle 中,放置会影响您在构建过程中所做的一切的依赖项,然后针对这些模块特定的每个模块依赖项。就是这么说的。

http://developer.android.com/tools/building/configuring-gradle.html

**编辑:**

Android Studio 文档:

Declare dependencies

The app module in this example declares three dependencies:

dependencies {
// Module dependency
compile project(":lib")

// Remote binary dependency
compile 'com.android.support:appcompat-v7:19.0.1'

// Local binary dependency
compile fileTree(dir: 'libs', include: ['*.jar']) } 

Each of these dependencies is described below. The build system adds all the compile dependencies to the compilation classpath and includes them in the final package.

Gradle 文档:

Example 7.1. Declaring dependencies

build.gradle

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

依赖项可以用多种不同的方式列出。