Ok, how do I publish this?

There are many ways to distribute an android library, so here’s a couple of them

This is probably the easiest one. You sign in with your Github account, add your repo, and you’re set!

The Jitpack process

2. jCenter

jCenter() is a central repository hosted by Bintray, and in order to publish your library there, you’ll have to create an account on bintray. If you’re planning on publishing an open-source library, you can sign up for a free open source account here. Otherwise, you can look into their paid plans for hosting private repositories.

Add a new repository to host your project

Create a repository on Bintray

Your new repository should now appear on your account. Open it, and add a new package

Create a package inside your new repository

Create a new package

Get an API key

Next, you need to get an API key to use it to push your library to the repository from Android Studio. Go to https://bintray.com/profile/edit, and choose API Key from the left menu.

Get an API key

You’re almost there! All you need to do now is add some Gradle scripts to your library

Add your username and API key to your local.properties file

Open your local.properties file (make sure it’s added to your .gitignore file!), and add the following:

Add the Bintray and Maven Gradle plugins to your project

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

Create the script for uploading your library package to Bintray

Thanks to Gradle’s modularity, we can extract all the scripts required to do this and put them in a single file. Inside your library package, create a new file called publish.gradle and paste this code in it.

Then in your project-level build.gradle file, add the following line to the bottom: apply from: 'publish.gradle'

The only things you need to care about in this file are these three lines: groupId, artifactId, version . Together, they make up the link to your library, so users can download it by doing this:

implementation 'groupId:artifactId:version’

Upload to Bintray

The last thing left to do is to publish your shiny new library to bintray so others can use it. So build your project, fire up the terminal in Android Studio and type 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 published and other people can use it. I hope you found this useful. You can see the code in action in my library here.