Getting Start Make Module AAR for Android Project (Local)

Introduce

AAR Format

The ‘aar’ bundle is the binary distribution of an Android Library Project.

The file extension is .aar, and the maven artifact type should be aar as well, but the file itself a simple zip file with the following entries:

  • /AndroidManifest.xml (mandatory)
  • /classes.jar (mandatory)
  • /res/ (mandatory)
  • /R.txt (mandatory)
  • /assets/ (optional)
  • /libs/*.jar (optional)
  • /jni//*.so (optional)
  • /proguard.txt (optional)
  • /lint.jar (optional)

These entries are directly at the root of the zip file.

The R.txt file is the output of aapt with –output-text-symbols.

In android’s view, bitmap,graphics, opengl and animation are included in graphics. The classes about shape will be introduced in this article. The other content will be introduced later.

Different between AAR and JAR

  • *.jar: contains only the class file and the manifest file, does not contain resource files, such as pictures, all res in the file.

  • *.Aar: contains all resources, class and res resource files are all included

Getting Started

Build a AAR

Create a new project, create a new module in the project, select Android jar, and then the next step next. After the new you will see in your module in the first line of the build.gradle file apply plugin: ‘com.android.library’, which represents it is a jar. Then run with

assembleRelease```, you will see an aar file in your project directory.
1
2
3
4
5
6
7
8
9
10
11
12
13

### Use AAR

1. the aar file on a file directory, such as on the libs directory

2. in the app build.gradle file to add the following

```java
Repositories {
     FlatDir {
         Dirs 'libs' // this way we can find the .aar file in libs folder
     }}
}}

  1. after the addition of a project to add a gradle dependency will be convenient to reference the library
1
2
3
Dependencies {
     Compile (name: 'test', ext: 'aar')
}}

ref:

build aar with gradle

android-reference-local-aar