Add dependency in android studio

Posted on

Question :

I wanted to know where exactly I put a dependency like this in android studio:



Answer :

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

Android Studio uses Gradle to manage dependencies and build applications.

There are two ways to declare a dependency in 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 jCenter repository to resolve dependencies, this is declared in build.gradle automatically when a new project.

repositories {


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

When I need something like: 1 – I search for dependency on google with the prefix “maven”
2 – on the repository site From maven, I click on the gradle tab that already gives the line that I should add in the gradle build script.



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


The link to the gradle text is a personal suggestion, as I found the approach quite interesting and straightforward.


Leave a Reply

Your email address will not be published. Required fields are marked *