Simple way to publish your Android library to JCenter

DEPRECATED. Read this: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

First of all, many thanks to Sittiphol Phanvilai for his original article. It is very detailed and has interesting digressions about the repositories and gradle. Please follow it if you want your library published on both JCenter and Maven Central.

Here is my slightly updated and very dried-out version that drives you directly to the point. Here is the source code for reference.

1. Setup your repository on Bintray

Sign Up for an Open Source Account

Click the “Add New Repository” button.

Give your repository a name, select “Maven” as a type. Optionally, specify a default license and type a description.

Click the “Add New Package” button, fill in the data. You could use your GitHub repository for the “website” and “issue tracker” fields.

Now you should be able to access your new package using the Bintray URL. Here is mine: https://bintray.com/lissf/maven/diagonalscrollview

2. Setup your Android library project

Check your Android project. I highly recommend you to make sure that your project has two modules: the Android Application (sample) and the Android Library.

Open your local.properties file (I hope it is in your .gitignore already, make sure that it is). Add your Bintray username and API key. You can get your key at https://bintray.com/profile/edit.

Open the build.gradle of your library module. You’ll have to add two plugins to help you package and publish the library.

To the same file add the following block. Set your data to every variable. Your library will be available as “publishedGroupId:artifact:libraryVersion”. It’s “ua.org.tenletters.widget:diagonalscrollview:0.3.3” for me.

To the bottom of the same file you should add this script:

This script is not supposed to be changed a lot, so it is safe to move it to a separate file and substitute it with this one line at the bottom of the build.gradle of your library module:

3. Package and upload your library

Now you should run two gradle commands.

First one is “install” to build your library and package everything that has to be published.

Second is “bintrayUpload” to, well, upload the files to Bintray.

After successful execution of theese commands, you should be able to see your package updated on https://bintray.com. New “version” should appear.

Now you may publish your library to JCenter. Click the “Add to JCenter” button.

In a few hours, you’ll receive an email. After that, everyone will be able to include your library to their Android projects with just one line.

Senior Android Developer, Raspberry Pi enthusiast, Dungeon Master.