As we have seen in our post, “How to develop first android Application/App in Android Studio” where we developed our first simple android application, now within this post we will see how we can convert this same application as a library to create AAR file which we can use from any other application as library. You can download the code from gihub as, $ git clone https://github.com/lynxbee/android-FirstAndroidApplication.git If you want to know more how to create this simple application, read the post HERE as mentioned above. Now, to convert this same application as library module, we will have to make following two changes in applications app/build.gradle file as, change “com.android.application” to “com.android.application” Delete line with “applicationId” $ git diff diff --git a/app/build.gradle b/app/build.gradle index c3fa8b5..9a5859f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,9 +1,8 @@ -apply plugin: 'com.android.application' +apply plugin: 'com.android.library' android { compileSdkVersion 28 defaultConfig { - applicationId "com.example.myapplication" minSdkVersion 15 targetSdkVersion 28 versionCode 1 Now, you are ready with the code to generate as library and can compile as, $ ./gradlew clean assembleRelease The generated library will be at, ./app/build/outputs/aar/app-release.aar You can download the source code from https://github.com/lynxbee/android-Application_to_Library
Command line execution
git clone https://github.com/lynxbee/android-FirstAndroidApplication.git If you want to know more how to create this simple application, read the post HERE as mentioned above. Now, to convert this same application as library module, we will have to make following two changes in applications app/build.gradle file as, change “com.android.application” to “com.android.application” Delete line with “applicationId” $ git diff diff --git a/app/build.gradle b/app/build.gradle index c3fa8b5..9a5859f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,9 +1,8 @@ -apply plugin: 'com.android.application' +apply plugin: 'com.android.library' android { compileSdkVersion 28 defaultConfig { - applicationId "com.example.myapplication" minSdkVersion 15 targetSdkVersion 28 versionCode 1 Now, you are ready with the code to generate as library and can compile as, $ ./gradlew clean assembleRelease The generated library will be at, ./app/build/outputs/aar/app-release.aar You can download the source code from https://github.com/lynxbee/android-Application_to_LibraryGotchas and common issues
Permission checks - verify user access rights and sudo privileges before executing system-level operations.
Environment configuration - double-check path variables and dependency versions to prevent runtime failures.
Backup safeguards - maintain configuration backups before applying system or database modifications.
Following these steps ensures clean configuration and reliable execution for convert an existing android application to a library module.
Comments and corrections