Manually adding aar with dependency pom/iml file
1. Publishing
In your aar project, add maven-publish
plugin and add necessary plugin configuration.
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
...
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.novoda:bintray-release:0.2.7'
}
...
publishing {
publications {
maven(MavenPublication) {
groupId 'com.example' //You can either define these here or get them from project conf elsewhere
artifactId 'example'
version '0.0.1-SNAPSHOT'
artifact "$buildDir/outputs/aar/app-release.aar" //aar artifact you want to publish
//generate pom nodes for dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dependency ->
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
}
//publish to filesystem repo
repositories{
maven {
url "$buildDir/repo"
}
}
}
Few things to note:
We're using a custom maven publication, so you have to define what is being published with the
artifact
clauseWe have to generate the pom ourselves, in the code above I'm using all compile config dependencies, you may want to make sure all the configs you care about are covered.
Running gradle publish
will publish to a maven repo structure to the repo
folder, which you can then consume from a different project.
2. Using published .aar
In a different android project, to use the aar published in #1:
In top level build.gradle:
allprojects {
repositories {
jcenter()
maven {
url "D:/full/path/to/repo"
}
}
}
add the path to earlier repo as a maven repository. Note that you may have to use the full path, because $buildDir
has a different value for this project. In your app build.gradle:
dependencies {
...
other dependencies
...
implementation ('com.example:example:0.0.1-SNAPSHOT@aar'){transitive=true}
}
transitive=true
is required for to fetch the transitive dependencies from the pom file.
Adding external dependecy to AAR file
OK so this wasn't the way to go about it for me.
I, eventualy, tried other methods and found the answer.
I posted my solution in this thread
How to add a local aar dependency into a bintray published library?
I ended up using Kezong:
apply plugin: 'com.kezong.fat-aar'
I will create a fat arr containing all the dependencies you want.
In your gradle.build file you and the dependency to your local aar like this:
embed project(path: ':myLocalARR-1.3.1-release')
Using embed will ensure that your final arr will contain the java files from your local dependency.
How add more than one aar file in build.gradle?
I got a way to do, just create a module, let's call it as base_lib, and put all your aars inside. All other modules implemate it. This is how my build.gradle file looks.
plugins {
id 'java-library'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
api fileTree(include: ['*.aar'], dir: 'libs')
}
Related Topics
Display Fb Profile Pic in Circular Image View in Application
Android Getorientation Azimuth Gets Polluted When Phone Is Tilted
Getlaunchintentforpackage Is Null for Some Apps
Android - Way to Appear Bordered Text on the Textview
Android - What Is the Meaning of Stableids
Align Top of Image to Top of Textview
How to Prevent Multiple Toast Overlaps
Get Last Inserted Value from SQLite Database Android
Android Mediaplayer/Videoview Error (1, -2147483648)
How to Parse the CSV File in Android Application
Android:Understanding Drawable Folder
Java.Lang.Noclassdeffounderror: Org.Ksoap2.Serialization.Soapobject
When Should One Use Rxjava Observable and When Simple Callback on Android