I have posted an article for creating an Android Library module in an Android Project and use that with the UI app module.
Please see the article if you need to know about creating the Library module in Android Project.
In this article, I will explain how we can generate the Android Archive(AAR) file for an Android Library module and Use that in different Android projects so that we can understand the Library creation can really save our redevelopment time cost by using the same module in different projects.
I will use Android Studio 4.0.2 and the same Project mention in the above-attached article.
I have created a project and a Library module It is shown below.
It is mentioned that I have created a Library Module named as currentTimeLib and I am using that module successfully within the project, now I will generate the AAR file and I will Import the AAR file into a different Android Project.
If you already know about creating the Library module then you can follow the steps directly.
Please follow the steps>>
Step1: Start the Android Studio and open the project where you want to generate the AAR file.
Step2: Click the Gradle option in right most corner of android studio.
Step3: You will see the App name in the window, please unfold the options in the sequence shown below.
It might take a few minutes, If the Build task is successfully completed It will show the message.
Step4: The generated AAR files will be located here(According to your Library name)
Step5: Now we can add the archive file into another Android Project so create a new Android Project.
Step6: After creating a new project >> Click on File>> Project Structure >> Modules >> “+” icon >>
Next>> The below window will have an option to select “Import AAR/JAR”
Next>> Click on next after selecting the “Import AAR/JAR” and in the next window select the AAR file path and click Finish.
Note: Take the AAR file generated in the previous project or use the AAR file you want to add.
Step7: Verify in settings.gradle file, the library module will be included.
Step8: Add the library module into the module Gradle file where this AAR file implementation is needed.
Step9: “Sync the project” and wait for the build successful.
Step10: Verify the classes available in the Library module is accessible in the module you have added the AAR file.
Step11: Now you can write the code for using the AAR library module in your Android Project.
Thanks!! Please add comments If you face any issues while implementing.