Android FAT AAR from Gradle

Carlos Macías Martín
AndroidPub
Published in
2 min readMar 26, 2019

Sometimes we need an Android library (AAR) to use it in another project or even platform. But exceptionally, we may need an AAR that contains more than just one library, what we’ll call from now on as FAT AAR.

An AAR contains the library JAR’s and also resources like drawable, layouts, etc; while a FAT AAR contains more than one AAR, so we don’t need to import lots of libraries, just one that contains everything we need.

Extracting AAR libraries from Gradle

Most of the times, we want to use libraries that we download through Gradle, but we don’t have the JAR or AAR file. For this matter we use this plugin.

The first step is to configure the buildscript to include this plugin:

The next step is to apply the plugin on the top of our library module build.gradle:

After that, we should specify the libraries we want to include in our FAT AAR. In order to do this, we must change “implementation” for “api”:

By default, the transitive dependencies are not added to the FAT AAR. If we want to add them, we must add this to our build.gradle:

Finally, in order to generate the FAT AAR we must rebuild the project. Then, in the project folder > build > outputs > aar, we will find the FAT AAR containing all the libraries we’ve specified. To check this, unpack the AAR with your favorite program and open the folder:

Inside “libs” folder, you’ll find all the JARs:

Now, imagine you dont want all those libraries and you need to delete one of them. You just delete it and then repackage with:

jar cvf myNewLib.aar -C tempFolder/ .

Finally, you have a FAT AAR that contains all the libraries you need, everything in one file!

If you have any question or suggestion, please leave it in the comments :)

EDIT: you can also take a look at Kezong, another FAT AAR tool. (Thanks to Mochamad Iqbal Dwi Cahyo for the contribution in the comments).

That’s all folks!

--

--

Carlos Macías Martín
AndroidPub

I love developing mobile apps, and I’m an enthusiast about programming and new technologies. I enjoy helping people solve their problems and needs.