In the last article, I mentioned how I got around to creating an Open-Source android library. In this post, we’ll take a look at how to publish your android library to Bintray. Once your library is published on bintray, it’ll be available to be used via gradle.
There are essentially 5 steps to publish your library on bintray:
- Create an open-source/paid account on https://bintray.com/
- Create your repository on Bintray.
- Install the bintray plugin on Android Studio.
- Upload the library to Bintray.
- Submit the library for review to be finally published.
1. Create an Open-Source/Paid account on https://bintray.com/
You cannot publish your library on Bintray if you don’t have an account for open-source or if it isn’t paid.
With an open-source account, your libraries would be publicly available for use. If you want your packages to be private, then sign up for a paid account. They have a Pro Edition and an Enterprise edition.
Since we’re talking about publishing an open-source library, we’ll create a open-source account here.
Follow the simple steps to create your account and activate it via confirmation mail. Once you’ve created your account, login and proceed to the next step.
2. Creating a Repository.
Let’s go ahead and create a repository for our android library. As you can see, I’ve already created one for pulsating button.
Go ahead and enter all the details for your repository. For library type, choose maven. For license, I think Apache 2.0 license works well.
Once your done filling up the form, go ahead and click create.
3. Installing the Bintray plugin on Android Studio
Creating and publishing the library is really easy with the novoda/bintray-release plugin. Let’s go ahead and setup this plugin.
- First, go to your project level build.gradle file and add this line for classpath:
Remember to replace <latest-version> with the latest version of the plugin. As of writing the latest version is 0.9.2
- Next, go to your app level build.gradle file and add this line to the top
Then go ahead and sync the project. We’ve finally setup the bintray plugin. Now we’re ready to upload our library to bintray.
4. Uploading the library to Bintray.
To upload our android library to bintray, we’ll need to add some configuration/credentials to our app level build.gradle file. This is how my build.gradle looks like for PulsatingButton.
Notice the publish block. This is required by the plugin to upload your android library to Bintray.All the credentials are pretty straightforward and you can find them in your Bintray account.
Finally, all we need to do is run an Android Studio command to upload our library.
You can find the bintray username on the top right corner in your Bintray account. For finding your Bintray Key Go to: Top Right Corner (Your username) -> Edit Profile -> API Key and copy your api key.
Replace the BINTRAY_KEY with the API key and BINTRAY_USERNAME with your username. Then open up the terminal on Android Studio and paste and run this command. Wait for it to finish successfully. Once the build finishes, your library will be uploaded to bintray and we just have to submit it for final review.
5. Submitting the library for Review
In this final step, we need to submit the library to JCenter for final review post which our android library will be published.
Go to Your Repository -> Click on your package and at the bottom right corner in the Linked To section, you’ll see an option to submit to JCenter.
Click on Add to JCenter and you’ll be redirected to a form where you’ll need to add information about your project. Then finally click on submit.
It takes mostly 24 hours to get your project reviewed and published on JCenter. You’ll receive a confirmation via mail that your android library has been published.
Now you’re ready to include your library into any project with Gradle!
Published on Java Code Geeks with permission by Ayusch Jain, partner at our JCG program. See the original article here: Publishing your Android Library to Bintray (Gradle)
Opinions expressed by Java Code Geeks contributors are their own.