Add dependency in android studio

3

I wanted to know 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>
    
asked by anonymous 10.11.2015 / 09:05

2 answers

1

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 {
    jcenter()
}
    
10.11.2015 / 12:38
1

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.

ToaddthedependencyinAndroidStudio,openthebuild.gradlefilefortheproject,andaddthedependencyinthedependencygroupasintheexampleofacompletescript:/p>

buildscript{repositories{mavenCentral()}dependencies{classpath'com.android.tools.build:gradle:1.0.0'}}applyplugin:'android'dependencies{compilefileTree(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{compileSdkVersion8buildToolsVersion"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 gradle text is a personal suggestion, as I found the approach quite interesting and straightforward.

    
10.11.2015 / 12:25