Wed. Oct 20th, 2021
Creating and Publishing an Android Library | by Adam Ahmed

There are some ways to distribute an android library, so right here’s a few them

  1. Jitpack

This might be the simplest one. You check in along with your Github account, add your repo, and you’re set!

The Jitpack course of

2. jCenter

jCenter() is a central repository hosted by Bintray, and with a view to publish your library there, you’ll should create an account on bintray. If you’re planning on publishing an open-source library, you may join a free open supply account right here. Otherwise, you may look into their paid plans for internet hosting non-public repositories.

Create a repository on Bintray

Your new repository ought to now seem in your account. Open it, and add a brand new bundle

Create a brand new bundle

Next, you want to get an API key to make use of it to push your library to the repository from Android Studio. Go to, and select API Key from the left menu.

Get an API key

You’re virtually there! All you want to do now could be add some Gradle scripts to your library

Open your file (ensure that it’s added to your .gitignore file!), and add the next:

In your app-level construct.gradle file, add these dependencies to your buildscript

Thanks to Gradle’s modularity, we will extract all of the scripts required to do that and put them in a single file. Inside your library bundle, create a brand new file known as publish.gradle and paste this code in it.

Then in your project-level construct.gradle file, add the next line to the underside: apply from: 'publish.gradle'

The solely issues you want to care about on this file are these three traces:groupId, artifactId, model. Together, they make up the hyperlink to your library, so customers can obtain it by doing this:

implementation 'groupId:artifactId:model’

The final thing left to do is to publish your shiny new library to bintray so others can use it. So construct your undertaking, fireplace up the terminal in Android Studio and sort down this command:

If you’re on Windows

gradlew bintrayUpload

If you’re on Linux/Mac

gradle bintrayUpload

That’s it! Your library is now printed and different individuals can use it. I hope you discovered this convenient. You can see the code in motion in my library right here.

By admin