Publish multi-module Android libraries on JitPack

If you're an Android developer and learned to love the benefits of open source, you may want to publish you're own libraries sometime. A common used services for building and providing Android libraries is JitPack. It's a user friendly alternative to jCenter, which takes a lot of pain from the process of publishing a library. It's as simple as adding a few lines of code to your project.

Now, given the case, that you already have an open source Android app, where you developed some special features (that may be helpful for other developers too), you don't want the other developers needing to copy parts of your app. You want to give them a library, they can simple add as dependency to there build.gradle file.

All you have to do is moving these features to a separate module in your project by using the Android Studio built-in feature to create library modules. Now you need to specify these modules as dependencies for you app module, move the .java (or .kt for Kotlin) files over to the library module and fix things if needed.

After you have done this, simply add this to your root build.gradle file into the buildscript dependencies (after the Android gradle plugin reference):

classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

And this to each library's build file:

apply plugin: 'com.github.dcendents.android-maven'  
group='com.github.USERNAME.REPO'

After this:

apply plugin: ‘com.android.library’

Of course you need to replace USERNAME and REPO with your Github username and the corresponding repository.

It’s almost done!

After your next push to Github and creating a new release, you’re modules will be available as separate libraries via:

compile 'com.github.USERNAME.REPO:MODULE:VERSION'

Make sure, that you add JitPack as a Gradle repository (how to do this is described on their page)!

Jan-Lukas Else
20 years old student who writes about everything he cares about.