Android Studio - Export the Android library aar with pure gradle


This question is so basic, and I didn't find documentation for it.

I have an Android Library project, and I would like to export an aar file of it, and use it in another project.

I have the following file, from so many other examples:

buildscript {
    repositories {

    dependencies {
        classpath ''

apply plugin: 'android-library'

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 7

I would like to use pure Gradle to run this, which means that I need to run the tasks, but first things first, I get the following error:

> Plugin with id 'android-library' not found.

Why does the plugin not found, and which tasks should I run?

Thanks, Adam.

Here's what has worked for me. It's manual, but it is a pure gradle way to do it. This assumes that you have 'apply plugin: "android-library" in your module's build.gradle file which I see you have.

  1. on the command line go to the root directory of the project
  2. ensure that your JAVA_HOME environment variable points to the version of the java sdk you are going to use. On a Mac via the bash shell that would look something like this:

    export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home'

(click here to find out how to find your Java Home)

  1. To clean type ./gradlew clean
  2. To build the library type ./gradlew aR (This may take a while)

You should now find the .aar file in mymodulename/build/outputs/aar

Thanks to [geekgarage] for clarification.2