Tomer
Tomer

Reputation: 559

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

I am requested to add a few dependencies. I know They should be added on build.gradle, but in the dependencies section is written:

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
}

I am new to android so from my small experience and googling there are supposed to be two build.gradle files, and only in one of them I should add dependencies, but I can not find an extra build.gradle file!?

I will be happy for help! Where should I add my dependencies and where did my second build.gradle disappear?

Upvotes: 2

Views: 4828

Answers (1)

BleuGamer
BleuGamer

Reputation: 307

Gradle is a bit of an odd tool. https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html

They state here how it works. There is only one build.gradle per project that will pull and manage dependencies for you.

Android Studio extends this. There is one 'main' build.gradle for the entire project, and then for each submodule there is a build.gradle since they are run as separate programs. in the master project build.gradle, put dependencies that effect everything you are doing in the build process, and then for each module dependencies specific for those modules. That's what it's saying.

App (submodule) and project gradle

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

**EDIT: **

Android Studio docs:

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 docs:

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.+'
}

Dependencies can be listed in a bunch of different ways.

Upvotes: 2

Related Questions