Creating Android Archive (AAR) file
This story explains steps to Android Archive (AAR) file with sample library application
What is AAR file?
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest. However, instead of compiling into an APK that runs on a device, an Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module.
Unlike JAR files, 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.
UtilsLibrary:
Step 1: Create an Android App.
Step2: Click File > New > New Module
In the Create New Module window that appears, click Android Library, then click Next.
Step3:Give your library a name (“utilslibrary”)and select a minimum SDK version for the code in the library, then click Finish.
After Android Studio completed the processing, observe your Android Library in the left pane. Now open project structure by using the following shortcut. Ctrl + Alt + Shift + S
Click on dependencies option in left side & select app module then press + in declared dependencies section, have a look.
Click on the Module dependency option in the top window, then a new window will be opened as shown below. Now select your library (“utilslibrary”)and click ok.
Implement logic in Library Module:
Create 2 packages with names “loggerutils” and “sharedprefsutils”
Once implementation is done , generate .aar files as below:
AAR file Generation:
Click on highlighted build option to generate “.aar “ file.
Where can we see .aar file?
How to use .aar file in the app?
please find below in which there is libs folder in which we will copy .aar file :
In the project level build.gradle , plz add below lines as highlighted:
In the app module level build.gradle, please add below line in dependencies :
How to use in Code:
Github Link: