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

Anitaa Murthy
5 min readMay 26, 2018

--

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

You can signup with your Github or Google account

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 libary project and click on Create

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:

classpath 'com.novoda:bintray-release:{latest_version}'

You can find the latest version here.

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

apply plugin: ‘com.android.library’publish {

def groupProjectID = '{package_name}'
def
artifactProjectID = '{name_of_your_library}'
def
publishVersionID = 'library_version_code'

userOrg = '{username_of_bintray}'
repoName = 'repository_name'
groupId = groupProjectID
artifactId = artifactProjectID
publishVersion = publishVersionID
desc = '{library description}'
website = '{github_url}

}
Sample build.gradle file under app/build.gradle

Step 5: Upload to Bintray

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

gradle clean build bintrayUpload -PbintrayUser={userid_bintray} -PbintrayKey={apikey_bintray} -PdryRun=false

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.

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:

Could not find method google() for arguments [] on repository container.

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:

brew upgrade gradle

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:

Unable to load class 'org.gradle.api.internal.component.Usage'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

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:

com.novoda.gradle.release.AndroidLibrary$LibraryUsage.getDependencyConstraints()Ljava/util/Set;

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.

//has to be BEFORE 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'com.android.library'

Issue IV:

:[MODULE-NAME]:bintrayUpload: Could not find publication: release.

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:

              //packageName:artifactId:versionId
implementation 'com.an.optimize:optimize:0.1.0'

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!

--

--