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
You can reference an aar file from a repository. A maven is an option, but there is a simpler solution: put the aar file in your libs directory and add a directory repository.
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
Then reference the library in the dependency section:
dependencies {
implementation 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
}
You can check out Min'an blog post for more info.
You can add multiple aar
dependencies with just few lines of code.
Add local flatDir
repository:
repositories {
flatDir {
dirs 'libs'
}
}
Add every aar
in libs
directory to compile
dependency configuration:
fileTree(dir: 'libs', include: '**/*.aar')
.each { File file ->
dependencies.add("compile", [name: file.name.lastIndexOf('.').with { it != -1 ? file.name[0..<it] : file.name }, ext: 'aar'])
}
I found this workaround in the Android issue tracker: https://code.google.com/p/android/issues/detail?id=55863#c21
The trick (not a fix) is to isolating your .aar files into a subproject and adding your libs as artifacts:
configurations.create("default")
artifacts.add("default", file('somelib.jar'))
artifacts.add("default", file('someaar.aar'))
More info: Handling-transitive-dependencies-for-local-artifacts-jars-and-aar
If you use Gradle Kotlin DSL, you need to add a file in your module directory.
For example: libs/someAndroidArchive.aar
After just write this in your module build.gradle.kts in dependency block:
implementation(files("libs/someAndroidArchive.aar"))
There are 2 ways:
The first way
Create New Module
window by File -> New -> New Module
Select the Import .JAR/.AAR Package
item and click the Next
button
Add a dependency in the build.gradle
file that belongs to your app
module.
dependencies {
...
implementation project(path: ':your aar lib name')
}
That's all.
The second way
Create a folder in libs
directory, such as aars
.
Put your aar lib into the aars folder.
Add the code snippet
repositories {
flatDir {
dirs 'libs/aars'
}
}
into your build.gradle
file belongs to the app module.
build.gradle
file that belongs to your app
module.dependencies {
...
implementation (name:'your aar lib name', ext:'aar')
}
That's all.
If you can read Chinese, you can check the blog 什么是AAR文件以及如何在Android开发中使用
In my case just work when i add "project" to compile:
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile project('com.x.x:x:1.0.0')
}