How to Publish Android Library on JCenter using Bintray

After you have finish building your own android library in android studio and you want to share your library with developer community, the next step is to publish your library on JCenter or Maven Central.

We are not going to cover how to publish your android library on Maven Central. If your focus is on Maven Central, I will suggest you read this tutorial on publishing your android library on Maven Central.

By the way, if you are writing this and you have not yet created your android library it is important you read my previous post on how to create your own android library.

Lets start with the process.

1. Create an Account on Bintray

If you do not have an account on Bintray, you will need to create a new account.

1. Follow this link to start with your account creation. Note that you can easily use your Github or Google account to login to Bintray.

publish android library

2. In your profile page, the first thing to do is to add a new repository.

3. Fill in detailed information about your repository. Select maven as the type and click on the create button once you are done.

4. If your Bintray repository was successfully created  it will redirect you to your repository page.

5. Click on Add a Package to add information about your package.

Once you are done filling the information about the package, click on the save button to save the details.

2. Open Your Android Project

Publishing library to JCenter or Maven can be a bit challenging for a first timer. So there is an android library that will simplify the whole process for us.

There might be others out there. So if you know of any other library apart from what we will use here kindly mention it in the comment box. We are going to use bintray-release android library created by Novoda.

Bintray-release is a helper library that provides an  easy way to release your Android and other artifacts to bintray.

1. Open your library build.gradlemodule and add the bintray-release plugin after the library plugin.

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

2. Open the project build.gradleand add the novoda-bintray-release classpath to it.

classpath 'com.novoda:bintray-release:0.9'

As you can see, the latest version of bintray-release as at writing this tutorial is 0.9. There might be a newer version by the time you are reading this tutorial so make sure you are using the latest version.

3. Lets go back again to our module build.gradlefile. We are going to add some details that will associate our android library project with bintray repository. Add the code below inside the build.gradle.

publish {
    userOrg = 'inducesmile.com'
    groupId = 'com.inducesmile.colorpickers'
    artifactId = 'ColorPicker'
    publishVersion = '0.1.0'
    repoName = 'AndroidColorPicker'
    desc = 'A simple android color picker library'
    website = 'https://github.com/HenryChigbo/Android-Color-Picker'
}

This is what the above attributes signifies.

userOrg – Repository owner

groupId – Package name of the project

ArtifactId – Library name

publishVersion – First version of the library

repoName – Name of the project Bintray repository

desc – Description of the library

website – Github repository for the project

3. bintrayUpload to Publish the Library

Finally we are going to use command line interface to execute the bintrayUpload command. This command will upload our library to our bintray repository.

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

Replace the bintray-userId and apiKey with real values.

You can get your Bintray API Key in your bintray profile page.

Once you hit enter, the upload process will start. Wait until it is successfully uploaded.

4. Add Bintray Repository to JCenter

Let’s open our Bintray repository page. You will see Add to Jcenter button. Click on the button to add your repository to JCenter.

Once you have added your library to Jcenter, it will take couple of hours before you will receive an email from Bintray notifying you that your library has been successfully published in Jcenter.

You can check your repository page to see the gradle link you can share with others developers who want to use your library.

5. Conclusion

This brings us to the end of how to publish android library on JCenter tutorial.

If you have an error in the course of following this tutorial, question or suggestion kindly use the comment box below to let us know.

 

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.