Manually adding aar with dependency pom/iml file - android

Since I cannot use a private maven in order to share my library, I was thinking in sharing the aar and importing into another project.
The problem comes when the aar and jar files does not contain any dependency. So once I manually import the aar in android studio (using Import .JAR/.AA Package) there is no dependency, and I have to manually add all dependencies again.
I already generated a pom file through a gradle task, although I cannot find any way to manually import it on the project.
On the build.gradle file automatically generated by the "Import .JAR/.AA Package" is:
configurations.maybeCreate("default")
artifacts.add("default", file('TestSample_1.0.0.aar'))
Is there a way to add the pom/iml file too? something like:
artifacts.add("default", file('pomDependencies.xml'))

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 clause
We 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.

Things have changed a little, here's how you do it with the latest versions of gradle
Create the package localy (aar and pom)
Modify your library build.gradle file to include
apply plugin: 'maven-publish'
android {
...
...
}
dependencies {
...
...
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.domain' //You can either define these here or get them from project conf elsewhere
artifactId 'name'
version '1.0.0'
artifact "$buildDir/outputs/aar/sdk-release.aar" //aar artifact you want to publish
//generate pom nodes for dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each { dependency ->
if (dependency.name != 'unspecified') {
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"
}
}
}
Run from terminal
./gradlew clean
./gradlew build
./gradlew --console=verbose publishToMavenLocal
The aar and pom files have been created at $HOME/.m2/repository/
How to load the library from a different project
Modify the projects's build.gradle in the following way:
allprojects {
repositories {
maven {
url "/Users/username/.m2/repository/"
}
google()
jcenter()
}
You can use $rootDir and set a relative path.
Add the library as a dependency in your app module build.gradle
implementation 'com.domain:name:1.0.0'

Related

Gradle Plugin 3.0.1 AAR transitive dependency missing [duplicate]

When I build an app with a *.aar file instead of the module with Gradle 4.x and following the docu concerning implements and api, I expect using api the included aar file has all dependencies included, but it hasn't.
When you do
git clone https://github.com/hannesa2/aar_dependency
./gradlew clean assembleDebug
means
dependencies {
api project(':mylibrary')
it works properly.
But when I use insted of lib-module the previous generated *.aar file as dependency
dependencies {
api 'com.example.my.mylibrary:mylibrary-debug#aar'
(in demo app just do)
git checkout with_aar
./gradlew clean assembleDebug
I run into this
Task :app:transformClassesWithDesugarForDebug
Exception in thread "main" java.lang.TypeNotPresentException: Type io.reactivex.ObservableTransformer not present
at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85)
at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:63)
at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41)
at java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067)
at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:399)
at org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(Unknown Source)
Because I ordinary run into this with uploading the aar artifacts into our company Maven Nexus, I created this demo-repo to show exactly what's wrong. In demo app or using Maven I see the same issue.
Does someone knows what I did wrong ?
I was able to solve it. The main issue was Android O with Gradle 4.x using api
dependencies {
api 'com.squareup.okhttp3:logging-interceptor:3.4.1'
api "io.reactivex.rxjava2:rxandroid:$versions.libs.rxAndroid"
Most answers are concerning something like this
publishing {
publications {
mipartner(MavenPublication) {
groupId '...'
artifactId '..'
version 1.0
artifact "$buildDir/outputs/aar/myLib-release.aar"
//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)
}
}
}
}
repositories{
maven {
url "https://some.url.com"
}
}
}
but here in the resulting *.pom there are no dependencies included, after change this line to api the dependencies are included in deployed pom !
configurations.api.allDependencies.each { dependency ->
after this you can easily consume the aar file
dependencies {
api "com.mylib.net:mylib:1.0"

including dependencies in generated pom of android library

I'm trying to publish an Android library to a local JFrog Artifactory. Currently I have this:
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'com.android.library'
publishing {
publications {
aar(MavenPublication) {
groupId libraryGroupId
version libraryVersion
artifactId libraryArtifactId
artifact("$buildDir/outputs/aar/app-beta-debug.aar")
}
}
}
artifactory {
contextUrl = 'http://localhost:8081/artifactory'
publish {
repository {
repoKey = 'libs-release-local'
username = artifactory_username
password = artifactory_password
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
publishPom = true
}
}
}
I have skipped some parts like android and dependencies sections for brevity. The build.gradle has multiple compile dependencies.
gradle artifactoryPublish
published the artifact to Artifactory but the generated pom doesn't have the dependencies. I found this answer: https://stackoverflow.com/a/30523571/2829308
from this answer, pom.withXml worked (although I couldn't figure out how to exclude a dependency). But this seems hackish. I feel like there should be a better way available. I tried using the uploadArchives way as follows
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/artifactory/libs-release-local")
pom.version = libraryVersion
pom.artifactId = libraryArtifactId
pom.groupId = libraryGroupId
}
}
}
It says task successful but artifact doesn't get published in Artifactory. Am I missing something obvious? How do I fix this?
Pom file shouldn't include transitive dependencies, only direct ones. Maven parses the pom files to find direct dependencies, download them and continue from there in a recursive manner.
The only dependencies that you should see in your pom file are the ones declared in the dependences block of your gradle script.

Gradle Artifactory Plugin - How to publish artifacts from multiple modules in a project?

I have a project which has a SharedCode (Java) module and secondly an Android (Android library) module which depends on the SharedCode module. I want to publish a jar artifact from the SharedCode module and an aar artifact from the Android module. I can't figure out how to compose my build.gradle files so that both modules publish to Artifactory when the artifactoryPublish task is run. At the moment only the SharedCode module publishes its artifact to Artifactory.
My build.gradle files are as below. Note that the maven-publish aspect of my build.gradle files appears to be correct because when I run the publishToMavenLocal task I see the artifacts from both modules in my local Maven folder (i.e. '~/.m2/repository').
Firstly, the build.gradle file in my SharedCode module is as follows:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
group = "${projectGroupId}"
version = "${projectVersionName}"
dependencies {
compile 'com.google.guava:guava:18.0'
}
publishing {
publications {
SharedCode(MavenPublication) {
groupId "${projectGroupId}"
artifactId 'SharedCode'
version "${projectVersionName}"
from components.java
}
}
}
artifactory {
contextUrl = "${artifactory_url}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_username}"
password = "${artifactory_password}"
}
defaults {
publications('SharedCode')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
Secondly, the build.gradle file in my Android module is as follows:
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
group = "${projectGroupId}"
version = "${projectVersionName}"
android {
// android stuff here...
}
dependencies {
compile project(':SharedCode')
}
publishing {
publications {
Android(MavenPublication) {
groupId "${projectGroupId}"
artifactId 'Android'
version "${projectVersionName}"
artifact "$buildDir/outputs/aar/Android-release.aar"
}
}
}
artifactory {
contextUrl = "${artifactory_url}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_username}"
password = "${artifactory_password}"
}
defaults {
publications('Android')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
If I run the artifactoryPublish task at the root, project level or at the SharedCode module level then I see output as follows:
18:23:38: Executing external task 'artifactoryPublish'...
Publication named 'SharedCode' does not exist for project ':Android' in task ':Android:artifactoryPublish'.
:SharedCode:generatePomFileForSharedCodePublication
:SharedCode:artifactoryPublish
Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/mycompany/sdk/SharedCode/0.0.2/SharedCode-0.0.2.jar
Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/mycompany/sdk/SharedCode/0.0.2/SharedCode-0.0.2.pom
Deploying build descriptor to: http://localhost:8081/artifactory/api/build Build successfully deployed.
Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/client-sdk/1457375019604
BUILD SUCCESSFUL
Note that only the SharedCode artifact is published in this case.
If I run the artifactoryPublish task at the Android module level, then I see output as follows:
18:25:25: Executing external task 'artifactoryPublish'...
Publication named 'SharedCode' does not exist for project ':Android' in task ':Android:artifactoryPublish'.
:Android:artifactoryPublish
Deploying build descriptor to: http://localhost:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/client-sdk/1457375127269
BUILD SUCCESSFUL
Note that no artifacts are published in this case.
Update: As of version 4.6.0 of the com.jfrog.artifactory Gradle plugin, publishing artifacts in a multi-module project just does not work. From personal experience, you're best just abandoning this plugin and using the standard maven-publish plugin for both Java library modules and Android library modules.
--- What follows below is my original answer before I posted the above update ---
So I've finally got this all working! Special thanks to #RaGe for helping me along the way. The key points to note are that the artifactory block needs to be in the project's root-level build.gradle file and not in the build.gradle file of the individual modules. Also, you need to add artifactoryPublish.skip=true to the project's root-level build.gradle file. See this GitHub repo for a full-on yet minimal-as-possible example:
https://github.com/adil-hussain-84/SO-35851251-Multiproject-Artifactory-Publish
In case the link ever stops working I'll paste the contents of the build.gradle files here also. Firstly, the project's root-level build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1'
}
}
allprojects {
apply plugin: 'com.jfrog.artifactory'
repositories {
jcenter()
}
group = "${projectGroupName}"
version = "${projectVersionName}"
}
artifactoryPublish.skip=true
artifactory {
contextUrl = "${artifactory_url}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_username}"
password = "${artifactory_password}"
}
defaults {
publications('SomePublication')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}
Secondly, the build.gradle file of the Android module:
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode Integer.parseInt("${projectVersionCode}")
versionName "${projectVersionName}"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':SharedCode')
compile 'com.android.support:appcompat-v7:23.2.1'
testCompile 'junit:junit:4.12'
}
publishing {
publications {
SomePublication(MavenPublication) {
artifact "$buildDir/outputs/aar/Android-release.aar"
//The publication doesn't know about our dependencies, so we have to manually add them to the pom
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.compile.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
Thirdly and finally, the build.gradle file of the SharedCode (Java) module:
apply plugin: 'java'
apply plugin: 'maven-publish'
dependencies {
compile 'com.google.guava:guava:18.0'
}
publishing {
publications {
SomePublication(MavenPublication) {
from components.java
}
}
}
That's it!
Going by artifactory multi-project examples on their github repo, it would seem that only the root project needs to have an artifactory{...} configuration section as opposed to in every sub-project as you have done.
Moreover when you declare publications('SharedCode') in the root project, artifactory plugin seems to be looking for a publication called sharedCode in every subproject.
I would try:
Remove the artifactory{...} section from the android build.gradle
Rename the android publication to sharedCode as well (or something more generic in both projects)
Version 4.2.0 of the Gradle Artifactory Plugin was released last week and added multiple Artifactory repositories deployment. Now you can simply define an artifactory closure with a different repository for different modules of the project.

Gradle: How to publish a Android library to local repository

I have a library and a Android app using Gradle and Android Studio. I can include the library directly in the project as following
compile project(':library')
Because I don't want to mesh up with library source code, I want to publish the library into local repository so that I can use as
compile 'com.mygroup:library:1.0'
Any advise?
I just found a solution. In the build.gradle of the library project, add this
apply plugin: 'maven'
group = 'com.mygroup'
version = '1.0'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://[your local maven path here]")
// or repository(url: mavenLocal().getUrl())
}
}
}
In the project folder, type following command
gradle uploadArchives
Read Publishing artifacts for more information
For an Android Library you should use the Android Gradle-Maven plugin https://github.com/dcendents/android-maven-gradle-plugin:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
Then to publish to your local repository run:
./gradlew install
which will install it in $HOME/.m2/repository. In your app or other project you can then include it by adding mavenLocal() to your repositories.
Alternatively, if your library is on GitHub then you can simply include it in other projects using JitPack. Then you don't have to run the above command and can just use what's been pushed.
Publish de library on your local maven repository and then on your gradle use
repositories {
mavenLocal()
}
If you have other repositories listed, make sure your mavenLocal appears first.
Docs: section 51.6.4 on https://gradle.org/docs/current/userguide/dependency_management.html
I prefer adding the java sources and the javadoc to the maven repository. The following script publishes your android library to a maven repository using the android maven plugin. It creates the .aar, javadoc.jar, sources.jar and .pom and updates the maven-metadata.xml after uploading the files to the maven repository. I also put the script on GitHub.
apply plugin: 'com.android.library'
apply plugin: 'maven'
//Your android configuration
android {
//...
}
//maven repository info
group = 'com.example'
version = '1.0.0'
ext {
//Specify your maven repository url here
repositoryUrl = 'ftp://your.maven.repository.com/maven2'
//Or you can use 'file:\\\\C:\\Temp' or 'maven-temp' for a local maven repository
}
//Upload android library to maven with javadoc and android sources
configurations {
deployerJars
}
//If you want to deploy to an ftp server
dependencies {
deployerJars "org.apache.maven.wagon:wagon-ftp:2.2"
}
// custom tasks for creating source/javadoc jars
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
destinationDir = file("../javadoc/")
failOnError false
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
//Creating sources with comments
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
//Put the androidSources and javadoc to the artifacts
artifacts {
archives androidSourcesJar
archives javadocJar
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: repositoryUrl) {
//if your repository needs authentication
authentication(userName: "username", password: "password")
}
}
}
}
Call it with
./gradlew uploadArchives
In settings.gradle add
include 'riz.com.mylibrary'
project(':riz.com.mylibrary').projectDir = new File('C:\\Users\\Rizwan Asif\\AndroidStudioProjects\\mylibrary')
Then in build.gradle in the dependencies add
compile project(':riz.com.mylibrary')

Adding local .aar files to my gradle build

So I have created an Android library and successfully compiled it into a .aar file. I called this aar file: "projectx-sdk-1.0.0.aar". Now I want my new project to depend on this aar so what I have done is follow this post.
But the post confuses me since I do not get the desired result:
The package name of the aar is : com.projectx.photosdk and the module inside is called sdk
Here is my current project structure:
|-SuperAwesomeApp
|--.idea
|--gradle
|--App
|---aars
|----projectx-sdk-1.0.0.aar
|---build
|---jars
|---src
|---build.gradle
And here is my Gradle build file:
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.projectx.photosdk:sdk:1.0.0#aar'
// compile files( 'aars/sdk-1.0.0.aar' ) // Does not work either
}
EDIT
The errors I am getting:
Failed to refresh Gradle project 'SuperAwesomeApp'
Could not find com.projectx.photosdk:sdk:1.0.0.
Required by:
SuperAwesomeApp:App:unspecified
You put your flatDir block in the wrong repostories block. The repositories block inside buildscript tells Gradle where to find the Android-Gradle plugin, but not the rest of the dependencies. You need to have another top-level repositories block like this:
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
I tested this and it works okay on my setup.
With recent versions of Android Studio, tested with 1.3, to use local .AAR file and not one fetched from maven/jcenter repository, just go to File > New > New module and choose Import .JAR/.AAR Package.
What you will end up with is a new module in your project that contains very simple build.gradle file that looks more or less like this:
configurations.create("default")
artifacts.add("default", file('this-is-yours-package-in-aar-format.aar'))
Of course, other projects have to reference this new module with regular compile project directive. So in a project that uses this new module which is simple a local .aar file has this in it's build.gradle
[...]
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
[...]
compile project(':name-of-module-created-via-new-module-option-described-above')
}
[...]
In Android Studio 3.1.3 with gradle 3.0.1.
Simply adding implementation fileTree(dir: 'libs', include: ['*.aar']) or implementation files('libs/app-release.aar') without any other flatdir works.
These days (over 1 year after this question) with Android Studio >1.0, local dependency does work properly:
The android sdk looks for dependencies in a default local repo of: $ANDROID_HOME/extras/android/m2repository/
In a local library project you can publish the aar to this directory. Here's a snippet that can be added to your module's build.gradle file (ex: sdk/build.gradle)
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost" + System.getenv("ANDROID_HOME")
+ "/extras/android/m2repository/")
pom.version = '1.0-SNAPSHOT'
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
some reference gradle docs http://gradle.org/docs/current/userguide/artifact_management.html
In your library project, run ./gradlew uploadArchives to publish the aar to that directory
In the application project you want to use the library in, add the dependency to your project/app/build.gradle. compile 'your.package:sdk-name:1.0-SNAPSHOT'
For local dependency, the next gradle build should find the previously deployed archive and that's it!
In my case, I use the above for local dev, but also have a Bamboo continuous integration server for the Library that publishes each build to a shared Nexus artifact repository. The full library code to deploy the artifact then becomes:
uploadArchives {
repositories {
mavenDeployer {
if (System.getenv("BAMBOO_BUILDNUMBER") != null) {
// Deploy to shared repository
repository(url: "http://internal-nexus.url/path/") {
authentication(userName: "user", password: "****")
}
pom.version = System.getenv("BAMBOO_BUILDNUMBER")
} else {
// Deploy to local Android sdk m2repository
repository(url: "file://localhost" + System.getenv("ANDROID_HOME")
+ "/extras/android/m2repository/")
pom.version = '1.0-SNAPSHOT'
}
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
In order to tell applications to download from my internal Nexus repository, I added the internal Nexus maven repository just above jcenter() in both "repositories" blocks in the project/build.gradle
repositories {
maven {
url "http://internal-nexus.url/path/"
}
jcenter()
}
And application dependency then looks like compile 'your.package:sdk-name:45' When I update the 45 version to 46 is when my project will grab the new artifact from the Nexus server.
With the newest Gradle version there is now a slightly updated way of doing what Stan suggested (see maving publishing)
apply plugin: 'maven-publish'
publishing {
publications {
aar(MavenPublication) {
groupId 'org.your-group-id'
artifactId 'your-artifact-id'
version 'x.x.x'
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
}
}
repositories {
maven {
url("file:" + System.getenv("HOME") + "/.m2/repository")
}
}
}
It seems adding .aar files as local dependency is not yet supported(Planned to be supported in 0.5.0 Beta)
https://code.google.com/p/android/issues/detail?id=55863
But the way you are using your library in dependency will only work if your library is on central maven repository or in the local maven repository.
Refer this for How to use local maven repository to use .aar in module dependencies.
http://www.flexlabs.org/2013/06/using-local-aar-android-library-packages-in-gradle-builds
This is for Kotlin DSL (build.gradle.kts) assuming you put the files in my-libs subdirectory relative to where the build file is located:
dependencies {
implementation(
fileTree("my-libs/") {
// You can add as many include or exclude calls as you want
include("my-first-library.aar")
include("another-library.aar")
// You can also include all files by using a pattern wildcard
include("*.jar")
exclude("the-bad-library.jar")
}
)
// Other dependencies...
}
For more ways to do this, see Gradle documentations and this post and this post.

Categories

Resources