Member-only story
How to Create an Android Archive (AAR) Library
Everything you should know about AAR.
Index
- The necessity of the Android library
- Why Android Archive (AAR)?
- Create a library module
- Dependencies in AAR file
- Implement your logic in your Library Module
- Gradle Rules you should be aware
- How to generate AAR file
- Real-time problems with solutions
- How to integrate AAR library
- Useful links
1. The necessity of the Android library
Android library is structurally the same as an Android app with resource files, source code, manifest file, and so on. However, instead of compiling into an APK, an Android library compiles into an Android Archive (AAR) file that you can use as a dependency so that we don’t need to create or write the same code all the time.
If you’re an android developer for a while, you should’ve at-least used one library (maybe support libraries 😉). If you see GitHub, it has many open source libraries for the date picker, Image Loading, and so on. The core intention of all these repository’s is to reuse the code.
The experience of creating my first Android library
A few days back I got a requirement to create a library with one of our app’s functionality so that it can be added as a mini-app.
2. Why an Android Archive (AAR)?
In this case, I thought of many ways, like creating a GitHub repo and publish it through JitPack. But the intention of the company is not to share the code, meaning the host app, which is integrating the library should not be able to see the logic part or whatever.
That’s when I come across JAR and AAR files.
JAR
With the JAR, we can only bundle java files, meaning it can’t include the layout or Gradle files. This type of library format is suited for projects that work on non-UI related tasks like parsing…