Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Export 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 gradle.build file, from so many other examples:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }
}

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.

like image 572
TacB0sS Avatar asked Jul 11 '13 18:07

TacB0sS


People also ask

What is difference between AAR and JAR?

The difference between JAR and AARJAR is just a Java library containing java class files and nothing more. AAR is a format for android libraries which contains a JAR file, android resource file (like layout XML, attribute XML, etc..) and an android manifest file.

Where is my AAR file in Android Studio?

It will show up in the build/outputs/aar/ directory in your module's directory. You can choose the "Android Library" type in File > New Module to create a new Android Library. If you are still not seeing your aar file, select Build > Rebuild Project .

What is .AAR file in Android Studio?

AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods. AAR files can contain C/C++ libraries for use by the app module's C/C++ code.


1 Answers

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

like image 198
Noah Ternullo Avatar answered Oct 21 '22 02:10

Noah Ternullo