Posted by on 11th December 2018

Create an Android library

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.

Why use Library Module

  • When building multiple apps that use some of the same components, such as activities, services, or UI layouts.
  • When building an app that exists in multiple APK variations, such as a free and paid version and you need the same core components in both.

In either case, simply move the files you want to reuse into a library module then add the library as a dependency for each app module. This page teaches you how to do both.


JitPack is a novel package repository for JVM and Android projects. It builds Git projects on demand and provides you with ready-to-use artifacts (jar, aar).JitPack supports building and installing from private Git repositories. Build artifacts are also kept private and you can only download them if you have access to the Git repository itself.  

Bitbucket Setup

To use JitPack with Bitbucket private repositories you need to create an App Password. The minimum scope that the password requires is Repositories: read. If you’d like to use Artifact Sharing then the required scope is Repositories: write.

In order to Look Up and manage Bitbucket repositories you should add the App Password to your JitPack account:

  1. Sign In on
  2. Click on your username (
  3. Enter your Bitbucket user and App Password

Your user page also shows your access token that you should use in your build tool (Gradle/Maven/Sbt).

Convert an app module to a library module

If you have an existing app module with all the code you want to reuse, you can turn it into a library module as follows:

  1. Open the module-level build.gradle file.
  2. Delete the line for the applicationId. Only an Android app module can define this.
  3. At the top of the file, you should see the following:
  4. apply plugin: ‘’
  5. Change it to the following:
  6. apply plugin: ‘’
  7. Save the file and click File > Sync Project with Gradle Files.

That’s it. The entire structure of the module remains the same, but it now operates as an Android library and the build will now create an AAR file instead of an APK.

Publish Your Android Library Process

  1. Add the following dependency to the project level root build.gradle file.

Publish Your Android Library Process

  2. In the library module build.gradle file, add the following two lines after the top line apply plugin: ‘’.

Note: In the group field replace the last string with your github username when you create your library.

Publish Your Android Library Process

3. Create and share project on Github or Bitbucket as a private repository.

Publish Your Android Library Process

4. Enter the following lines in the terminal present in Android Studio.

Note: Each time you do changes in the library, you need to update the version numbers in the above lines.

Library Usage Process

1.  Open JitPack(, sign-in and search your repository by the url. (i.e. amitresearchdev/Sample6 <Username>/<Libraryname>)

Library Usage Process

2. Clicking on Get It would show you the dependency url. Follow the instructions below.

Library Usage Process

3. Typically you’ll need to add the following in the root build.gradle.

Merge multiple manifest files

Your APK file can contain just one AndroidManifest.xml file, but your Android Studio project may contain several—provided by the main source set, build variants, and imported libraries. So when building your app, the Gradle build merges all manifest files into a single manifest file that’s packaged into your APK.

Merge Priorities

The merger tool combines all the manifest files into one file by merging them sequentially based on each manifest file’s priority. For example, if you have three manifest files, the lowest priority manifest is merged into the next highest priority, and then that is merged into the highest priority manifest, as illustrated in figure


Please follow and like us:
Posted in: Android, Android Library


Be the first to comment.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Enjoy this blog? Please spread the word :)