On your library build.gradle put this:
On your application that should use this library put this to the project build.gradle:
On the app build.gradle put this:
Useful links:
publishing {
publications {
libary(MavenPublication) {
groupId 'com.libary.api.android'
artifactId 'libary'
version '0.1'
artifact("$buildDir/outputs/aar/library-release.aar") pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dp->
if (dp instanceof ModuleDependency) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dp.group)
dependencyNode.appendNode('artifactId', dp.name)
dependencyNode.appendNode('version', dp.version)
}
}
}
}
}
repositories {
maven {
url "c:/Bit/AndroidExample/build/repo" }
}
}
Execute this on the folder where project with library is located:
gradlew clean build publish
Now folder repo is created with our library in .aar format where our class builded and packed on .zip format. Also there is .pom file with our dependencies.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0' }
}
allprojects {
repositories {
jcenter()
maven {
url "c:/path_to_local_repo/repo" }
}
}
On the app build.gradle put this:
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs' }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0'
compile ('com.libary.api.android:libary:0.1@aar'){transitive=true}
}
Useful links: