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 Bintray and set up your account there.
- Go to Home โ Repository and create a 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:
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Required plugins added to classpath to facilitate pushing to Jcenter/Bintray
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
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:
ext {
// This should be same as you've created in bintray
bintrayRepo = 'maven'
// Name which will be visible on bintray
bintrayName = 'CoolLibrary'
// Library Details
publishedGroupId = 'dev.shreyaspatil'
libraryName = 'CoolLibrary'
artifact = 'CoolLibrary'
libraryDescription = 'Cool Library'
libraryVersion = version
// Repository Link (For e.g. GitHub repo)
siteUrl = 'https://github.com/patilshreyas/AndroidLibDemo'
gitUrl = 'https://github.com/patilshreyas/AndroidLibDemo.git'
githubRepository= 'patilshreyas/AndroidLibDemo'
// Developer Details
developerId = 'patilshreyas'
developerName = 'Shreyas Patil'
developerEmail = 'shreyaspatilg@gmail.com'
// License Details
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
// This is mandatory
group = publishedGroupId
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
groupId publishedGroupId
artifactId = artifact
name libraryName
description = libraryDescription
url siteUrl
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
// Avoid Kotlin docs error
tasks.withType(Javadoc) {
enabled = false
}
// Remove javadoc related tasks
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
// https://github.com/bintray/gradle-bintray-plugin
bintray {
user = System.getenv("bintrayUser")
key = System.getenv("bintrayApiKey")
configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
}
}
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.
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.
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, 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.
name: Publish Bintray
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Grant Permission to Execute
run: chmod +x gradlew
- name: Publish Library
env:
bintrayUser: ${{ secrets.BINTRAY_USER }}
bintrayApiKey: ${{ secrets.BINTRAY_API_KEY }}
run: ./gradlew bintrayUpload
Note: Notice that weโve exposed system environment variable
bintrayUserandbintrayApiKeywhich values weโre getting from GitHub secrets. Remember that weโre reading these values inbuild.gradleusingSystem.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. ๐:


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โฆ