Adding local .aar files to my gradle build Adding local .aar files to my gradle build android android

Adding local .aar files to my gradle build


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.