Home » Android » Convert an existing Android application to a library module

Convert an existing Android application to a library module

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,

  1. change “com.android.application” to “com.android.application”
  2. 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

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment