How to manually include external aar package using new Gradle Android Build System How to manually include external aar package using new Gradle Android Build System android android

How to manually include external aar package using new Gradle Android Build System


Please follow below steps to get it working ( I have tested it up to Android Studio 2.2)

Lets say you have kept aar file in libs folder. ( assume file name is cards.aar )

then in app build.gradle specify following and click sync project with Gradle files.Open Project level build.gradle and add flatDir{dirs 'libs'} like did below

allprojects {   repositories {      jcenter()      flatDir {        dirs 'libs'      }   }}

and now open app level build.grdle file and add .aar file

    dependencies {       implementation(name:'cards', ext:'aar')}

If everything goes well you will see library entry is made in build -> exploded-aar

Also note that if you are importing a .aar file from another project that has dependencies you'll need to include these in your build.gradle, too.


  1. Right click on your project and select "Open Module Settings".

Open module settings

  1. Click the "+" button in the top left corner of window to add a new module.

Add new module

  1. Select "Import .JAR or .AAR Package" and click the "Next" button.

Import AAR

  1. Find the AAR file using the ellipsis button "..." beside the "File name" field.

Find AAR file

  1. Keep the app's module selected and click on the Dependencies pane to add the new module as a dependency.

Dependencies pane

  1. Use the "+" button of the dependencies screen and select "Module dependency".

Add module dependency

  1. Select the module and click "OK".

Choose module

EDIT: Module dependency in screenshot 6 has been removed in Android Studio 4.1. As an alternative add the module dependency to the build.gradle.

dependencies {    implementation project(':your_module')}

EDIT: The user interface and the work flow have been changed a lot in Android Studio 4.2. The process to add a dependency is very well explained in an official documentation now: Adding dependencies with the Project Structure Dialog


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.