So i have created a Android-Library and succesfully 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 did is follow this post: http://life.nimbco.us/referencing-local-aar-files-with-android-studios-new-gradle-based-build-system/
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 he 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
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
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:
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
You put your
flatDir
block in the wrongrepostories
block. Therepositories
block insidebuildscript
tells Gradle where to find the Android-Gradle plugin, but not the rest of the dependencies. You need to have another top-levelrepositories
block like this:I tested this and it works okay on my setup.
These days (over 1 year after this question) with Android Studio >1.0, local dependency does work properly:
$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)./gradlew uploadArchives
to publish the aar to that directorycompile '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:
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
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.In Android Studio 3.1.3 with gradle 3.0.1.
Simply adding
implementation fileTree(dir: 'libs', include: ['*.aar'])
orimplementation files('libs/app-release.aar')
without any otherflatdir
works.With the newest Gradle version there is now a slightly updated way of doing what Stan suggested (see maving publishing)