I am having one .aar
file of one library module.
I want to use it as a library or dependency in my other project's library module.
How do I do it?
I tried options provided at below links:
http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project/
It works only if I add .aar
reference in my project's application module. But not working in library module.
Thanks.
Follow this setting and you will able to add .aar
dependency to library module
build.gradle (Project: ....)
allprojects {
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'libs'
dirs project(':library_module').file('libs')
}
}
}
build.gradle (Module: app)
dependencies {
...
compile project(':library_module')
}
build.gradle (Module: library_module)
dependencies {
...
compile(name:'aar_file_name', ext:'aar')
}
settings.gradle (Project Settings)
include ':app', ':library_module'
In all modules (library or application) where you need the aar file you have to add in your build.gradle
the repository:
repositories {
flatDir {
dirs 'libs'
}
}
and add the dependency:
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
You can use the top-level file to add the repositories, but you can't add the dependencies in the top-level file.
Pay attention to the relative path of the libs folder that you are using in the module.
- File -> New Module -> Import .JAR/.AAR
- import the .AAR file.
- in library module build.gradle add the dependency
dependencies{compile project(':Name-Of-Your-Module-aar')}
http://tools.android.com/tech-docs/new-build-system/tips#TOC-Handling-transitive-dependencies-for-local-artifacts-jars-and-aar-