I\'ve been experimenting with the new android build system and I\'ve run into a small issue. I\'ve compiled my own aar package of ActionBarSherlock which I\'ve called \'act
Currently referencing a local .aar file is not supported (as confirmed by Xavier Ducrochet)
What you can do instead is set up a local Maven repository (much more simple than it sounds) and reference the .aar from there.
I've written a blogpost detailing how to get it working here:
http://www.flexlabs.org/2013/06/using-local-aar-android-library-packages-in-gradle-builds
For me, this was an issue with how Android Studio environment was configured.
When I updated the File
-> Project Structure
-> JDK Location
to a later Java version (jdk1.8.0_192.jdk
- for me), everything started working.
In my case I have some depencies in my library and when I create an aar
from it I failed, because of missed depencies, so my solution is to add all depencies from my lib with an arr
file.
So my project level build.gradle
looks so:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
mavenCentral()
//add it to be able to add depency to aar-files from libs folder in build.gradle(yoursAppModule)
flatDir {
dirs 'libs'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(modile app)
so:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.sampleapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//your project depencies
...
//add lib via aar-depency
compile(name: 'aarLibFileNameHere', ext: 'aar')
//add all its internal depencies, as arr don't have it
...
}
and library build.gradle
:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//here goes library projects dependencies, which you must include
//in yours build.gradle(modile app) too
...
}
I've also had this problem. This issue report: https://code.google.com/p/android/issues/detail?id=55863 seems to suggest that directly referencing the .AAR file is not supported.
Perhaps the alternative for now is to define the actionbarsherlock library as a Gradle library under the parent directory of your project and reference accordingly.
The syntax is defined here http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Referencing-a-Library
I've just succeeded!
Copy the mylib-0.1.aar file into the libs/ folder
Add these lines to the bottom of build.gradle (should be app, not project):
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'com.example.lib:mylib:0.1@aar'
}
So far so good. Here comes the most important point:
Gradle needs to access the network for dependencies unless offline mode is enabled.
Make sure that you have enabled Offline work via the checkbox in Project Structures/Gradle
-- OR --
Configure the proxy settings in order to access the network.
To configure the proxy settings you have to modify the project's gradle.properties file, configuring http and https separately as below:
systemProp.http.proxyHost=proxy.example.com
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=user
systemProp.http.proxyPassword=pass
systemProp.http.nonProxyHosts=localhost
systemProp.http.auth.ntlm.domain=example <for NT auth>
systemProp.https.proxyHost=proxy.example.com
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=user
systemProp.https.proxyPassword=pass
systemProp.https.nonProxyHosts=localhost
systemProp.https.auth.ntlm.domain=example <for NT auth>
Hope this works.
The below approach works with latest Android studio (> v0.8.x):
Save the aar
file under app module's libs
folder (eg: <project>/<app>/libs/myaar.aar
)
Add the below to build.gradle of your "app" module folder (not your project root build.gradle). Note the name in compile line, it is myaar@aar not myaar.aar.
dependencies {
compile 'package.name.of.your.aar:myaar@aar'
}
repositories{
flatDir{
dirs 'libs'
}
}
Click Tools -> Android -> Sync Project with Gradle Files