Skip to content
Shreyas Patil's Blog

๐Ÿค– Automate Publishing Android Library to Bintray using GitHub Actions ๐Ÿš€

Cover image for ๐Ÿค– Automate Publishing Android Library to Bintray using GitHub Actions ๐Ÿš€

In this article, Iโ€™m going to demonstrate the use of GitHub Actions to publish open-source Android Library to Bintray when it is released.

You might have developed a cool open-source android library ๐Ÿ› ๏ธ. You have published it to Bintray/JCenter. Right? But youโ€™re publishing it manually using Gradle CLI ./gradlew bintrayUpload command. After you made changes in your library, you always run Gradle command manually. Want to see how you can automate publishing it using GitHub Actions CI? Then you are at the right place.

We will see how to publish your open-source cool android library to Bintray automatically when we create a new release in GitHub repository. So, letโ€™s start ๐Ÿ˜ƒ.

Before starting, youโ€™ll need to do some tasks with Bintray profile. If youโ€™ve already done, you can skip this part and directly go to the next part โšก.


๐Ÿ’ป Setup Bintray ๐Ÿ› ๏ธ

Thus, youโ€™re done with Bintray set up. Now letโ€™s see the Android part.


๐Ÿ’ป Android Library Set up

In build.gradle of your project module, ensure that youโ€™ve below plugins added:

Add these plugins in the build.gradle file of the library module:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

Now, weโ€™ve to set up library configuration ๐Ÿ›  for the Bintray in this file. Just append build.gradle file of library module with the code as below:

About these variables:

Note: Notice that weโ€™re reading Bintray User and Bintray API Key from the system environment variable using System.getenv() method. This will be significant in the GitHub Actions Workflow setup.

Now, youโ€™ve done this part and now push your code to the GitHub repo for next step.


๐Ÿ’ป Setting up on GitHub

Go to Settings โ†’ Click Add new Secret. Youโ€™ve to add two secret values for this repo: BINTRAY_USER and BINTRAY_API_KEY.

After adding these secrets, it should look as below ๐Ÿ‘‡:

GitHub Repository Secrets


๐Ÿ’ป Setting up GitHub Actions Workflow

Now just create a workflow file named publish.yml which will be responsible to publish your library automatically on every release.

Just create a .github directory at the root of GitHub repository. Under it, create workflows directory and put the below file in this. So the path would be .github/workflows/publish.yml. Or simply, you can directly create the workflow by clicking the Actions tab and then create Workflow from available templates.

Note: Notice that weโ€™ve exposed system environment variable bintrayUser and bintrayApiKey which values weโ€™re getting from GitHub secrets. Remember that weโ€™re reading these values in build.gradle using System.getenv() method.

Finally, itโ€™s running a command ./gradlew bintrayUpload which will publish your library to the Bintray!


Test it! ๐Ÿ˜ƒ

Now letโ€™s test if it is working or not.

Go to Releases of your repository and click Create new Release and create release as below and click Publish Release ๐Ÿ‘‡:

After you click Publish release, that workflow we created earlier will be triggered and it will start its execution.

Now just navigate to Actions tab of your GitHub repo and notice that your Action is running. Finally, after execution is done, youโ€™ll see the result as below! ๐Ÿ‘‡:

Yeah ๐Ÿ˜!!! Your cool open-source Android library is just successfully published in Bintray JFrog repository. Letโ€™s verify it. ๐Ÿ˜ƒ

Go to your Bintray account and open Maven repository you created earlier and see your library is listed there. Now, officially your library is published and it can be imported in Android projects. ๐Ÿ‘‡:

Bintray Repositories

Your package details on Bintray

This is how we automated publishing your cool open-source android library to Bintray using GitHub Actions.

In the future, you will not need to manage it manually ๐Ÿ˜Ž. You just make changes in the library and create Release on GitHub and a new version of the library will be automatically published to the Bintray and itโ€™ll be live in a few seconds ๐Ÿš€.

Yeah ๐Ÿ˜! Hope you liked that. If you find it helpful please share this article. Maybe itโ€™ll help someone needy!

Thank you ๐Ÿ˜„!


Sharing is Caring!


๐Ÿ“š Resources

Here is a repository that contains the code used in this article:

PatilShreyas/AndroidLibDemo - GitHub

If you want to contact me, feel free to reach meโ€ฆ

shreyaspatil.dev



Previous Post
๐ŸŒŠ StateFlow, End of LiveData?
Next Post
๐Ÿ”ฅFirebase-ing with Kotlin Coroutines + Flow ๐ŸŒŠ