Implementation of .aar in large project

Sanket Vekariya
3 min readDec 30, 2019

--

Recently I dived into an important task how to minimize the application size and it’s build time in which I was working. The project was taking too much time to be built with Gradle as well as running it on emulator. (:( It sucks because of its 500MB+ size with 11 modules). In the beginning, a thought came to my mind why to compile all the files again and again which I haven’t changed at all?

Please God, Don’t curse the android developer :-(

I researched and came to the temporary conclusion that .jar file can help me out with this problem. But at the time of accessing activity and resources with .jar, I failed to do so. I tried with .aar files afterwards and it worked fine.

I want to share some outcomes of my research with .aar files as below.

Let’s consider a scenario that I have module 1, module 2, module 3 libraries and base module application project. I want to combine module 1 and 2 “AS A LIBRARY” inside library module 3.

Library Module 1, 2, and 3 configurations
Base module configurations

The issues were something like below.

  1. There are nearly 40 developers for the project having 11 modules which were making calls from anywhere to everywhere… Every developer had to compile the whole project unwillingly and run even if there is a single line of change (FYI: hot reload is not possible for such larger projects :( )
  2. Redundancy of resources was at it’s the extreme pick.
  3. Library implementations were redundant and different from other modules.

To solve these issues in the project, I tried below.

  1. Created released .aar files of library modules and implemented as a dependency in application module.
Demo Implementation

2. That .aar file allowed me to access class files of that module directly (not actual file) and resources inside manifest, other module’s classes, etc.

Some Conclusions :

Different Test Case Scenarios

Diverse Conclusions :

I tried to create like a hub from where we can access any of the modules, but found a diverse conclusion that,

We cannot combine two libraries inside a single library, because internally the parent library can’t distinguish between those 2 child library’s classes.jar files created internally inside .aar file.

This can be one of the approaches of minimizing app size and it’s build time as well.

Git Project Link : https://github.com/sanket-vekariya/test_module_project

Found this article helpful? Please clap and share.

Comment your thoughts, issues, questions and research you have done with .aar.

--

--

Sanket Vekariya

Google Associate Android Developer | Flutter Developer | Earning Experience by Learning Lessons