Add dependency on android studio

Asked

Viewed 3,258 times

3

I wondered where exactly I put a dependency like this in android studio:

<dependency>
  <groupId>com.code-troopers.betterpickers</groupId>
  <artifactId>library</artifactId>
  <version>2.2.1</version>
  <type>aar</type>
</dependency>

2 answers

1

Android Studio uses the Gradle as Database and dependency manager, but still uses the Maven central repository to resolve these dependencies.

When I need something like:
1 - i search for the dependency on google with the prefix "Maven"
2 - on the site of the Maven repository, I click on the Gradle tab that already gives the line that I should add in the Gradle build script. inserir a descrição da imagem aqui

To add the dependency on Android Studio, open the project’s build.Radle file, and add the dependency on the group dependency as in the example of a complete script:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'log4j:log4j:1.2.11'
    compile 'de.mindpipe.android:android-logging-log4j:1.0.2'
    compile 'org.roboguice:roboguice:3.+'
    provided 'org.roboguice:roboblender:3.+'

    compile 'com.code-troopers.betterpickers:library:2.0.3'

}

allprojects {
    repositories {
        mavenCentral()
    }
}

android {
    compileSdkVersion 8
    buildToolsVersion "19.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

The link to the text of Gradle is a personal suggestion, because I found quite interesting and direct approach.

1


This format you indicated is the format used by Maven to declare a dependency.

The Android Studio uses Gradle to manage dependencies and build applications.

There are two ways to declare a dependency on Gradle:

Using the identifiers group, name and version

dependencies {
    compile group: 'com.code-troopers.betterpickers', name: 'library', version: '2.2.1'
}

Using the short form group:name:version

dependencies {
    compile 'com.code-troopers.betterpickers:library:2.2.1'
}

Android Studio uses the repository jCenter to resolve dependencies, this is stated in build.Gradle automatically when a new project is created.

repositories {
    jcenter()
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.