6 easy steps to upload your Android library to Bintray/JCenter

Anitaa Murthy
May 26, 2018 · 5 min read

As part of being a developer, we always write code that can be reused in a lot of places. Rather than copy and paste, it is easier for us to write it once and reuse it wherever we want. But if we really want to be productive we can just add the code to a library and reuse it. This article focuses on how to upload an android library to bintray and some of the issues I have faced along the way.

So let’s begin!

Step 1: Create an account in Bintray

Note: you can also create a private account, but I think you need to activate a monthly subscription plan. But for now, we are creating a free account, which means all the projects added to Bintray should be open sourced.

Step 2: Add a repository in Bintray

Click on Add New Repository. You should be redirect to the below screen.

Enter details of the library project and click on Create. You will be redirected to the following screen if all goes well.

Step 3: Open your library project in Android Studio

I assume you have already added the project as a library.

Now, let’s add the bintray to our project. There is a great plugin that is available which makes it super easy to upload our library to bintray. Let’s add that to our project.

Add the following code under the root build.gradle file:

You can find the latest version here.

Step 4: Add project details to the build.gradle file under the /app directory

Step 5: Upload to Bintray

In the terminal in Android Studio, add the below command to clean, build and upload the library to bintray:

Note: the items marked in bold need to be filled by you. The userId is your bintray userId and the key is the api key. You can find the api key in bintray website -> Edit Profile -> Api Key.

Step 6: Link to JCenter

Under your project repository in Bintray, you will see your library along with the version details you had specified. Now all you need to do is click on Add to JCenter.

And that’s it! You have to wait until you get a notification in bintray that your library has been accepted to join JCenter before anyone can begin to use your library.


Bonus:

Now, if you are anything like me, then you must have faced one of the below issues when trying to follow the steps above. I thought of highlighting the issues I’ve faced so it would be helpful to someone else in the future.

Issue I:

Cause: I found out that this issue was because I had recently updated the android studio to 3.1 and so gradle had to be upgraded to the latest version as well in my local system.

Solution: I updated my local gradle from 3.1 to 4.6 (which was the latest at the time of the article). I am using a Mac so I just used the below command to upgrade gradle to the latest version:

Note: you need to install homebrew first in order to execute the above command. How to install homebrew is given here.

For windows people, please use this guide to update gradle.

Issue II:

Cause: This problem appears because the gradle I used is version 3.4.1, and it is not compatible with the plugin ‘com.novoda:bintray-release:0.4.0’ ‘s gradle version.

Solution: Updating to the latest version of the plugin i. e. com.novoda:bintray-release:0.8.0.

Issue III:

Cause: For some reason, in the latest version of the plugin, I keep getting this error. An open issue is already added to GitHub. Cause yet not known.

Solution: Again not sure what the cause is but for some reason, when we add the plugin first before the library plugin, it seems to work.

Issue IV:

Cause: Again, this is an open issue and the cause is not yet found. Once the cause is identified, I will update it here.

Solution: But a workaround has been found which seems to be working.


Once your library is uploaded to bintray and has been accepted, you can use your library. For example, my dependency looks like this:

And that’s it guys! Hope this article was useful. If you thought this was a good article, please don’t forget to clap. Thanks for reading.

Happy coding!

Anitaa Murthy

Written by

Android Developer/iOS Developer https://github.com/anitaa1990

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade