đ€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đ ïž:
- Visit https://bintray.com and set up your account there.
- Goto Home â Repository and create maven repository and keep its name of your choice. Iâve named it âmavenâ. (Remember, itâll be useful in upcoming steps.)
- After this, itâll look like below. Click Edit
- Select API Key from the left menu and Copy or Keep this API Key for future reference.
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.application'
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 â
bintrayRepo
â Name of the repository youâve created in previous steps.bintrayName
â Name which will be visible on Bintray.- Change the values of other fields of your choice.
Notice that weâre reading Bintray User and Bintray API Key from the system environment variable using
System.getenv()
method. Youâll understand itâs significance in upcoming steps(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. i.e. âBINTRAY_USERâ and âBINTRAY_API_KEYâ.
BINTRAY_USER
â Your Bintray UsernameBINTRAY_API_KEY
â Your Bintray API Key (Which youâve copied in the previous step).
After adding these secrets, it should look as belowđ.
đ»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, createworkflows
directory and put below file in this. So 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.
Notice that weâve exposed system environment variable
bintrayUser
andbintrayApiKey
which values weâre getting from GitHub secrets. Remember that weâre reading these values in build.gradle usingSystem.getenv()
method.
Finally, itâs running a command ./gradlew bintrayUpload
which will publish your library to the Bintray!
Thus, youâve done setup.
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. đ
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!
Resource â
Here is a repository that contains the code used in this article.
If you want to contact me, feel free to reach meâŠ