GitHub actions is really amazing because you can literally build your apps with just a push of your code to GitHub. I’ve been playing with GitHub actions lately and I really really love it. I’ve used GitHub actions before to build Python packages and Electron apps and I thought that why not for Android as well.
Before getting started, complete the following steps:
- Encode your KeyStore file (.jks) to base64.
openssl base64 -A -in keystore.jks -out base64.txt
- Copy the content of base64.txt and store it as SIGNINGKEYBASE64 in GitHub secrets.
- Store your alias as ALIAS in GitHub secrets.
- Store your keystore password as KEYSTOREPASSWORD and key password as KEYPASSWORD in GitHub secrets.
Now in your project create a folder “.github” and inside this folder create a folder “workflows”. Inside workflows folder create a file “build.yml” and add the below content in build.yml.
name: Build | |
on: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
Build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: kaisugi/action-regex-match@v1.0.0 | |
id: regex-match | |
with: | |
text: ${{ github.event.head_commit.message }} | |
regex: '^v[0-9]+\.[0-9]+\.[0-9]+$' | |
- name: Setup JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
cache: 'gradle' | |
- name: Build App | |
run: | | |
bash ./gradlew assembleRelease | |
bash ./gradlew bundleRelease | |
- name: Move files | |
if: ${{ steps.regex-match.outputs.match != '' }} | |
run: | | |
mv app/build/outputs/apk/release/app-release-unsigned.apk app/build/outputs/app-release.apk | |
mv app/build/outputs/bundle/release/app-release.aab app/build/outputs/app-release.aab | |
- name: Sign App | |
if: ${{ steps.regex-match.outputs.match != '' }} | |
id: sign_app | |
uses: ilharp/sign-android-release@v1.0.4 | |
with: | |
releaseDir: app/build/outputs | |
signingKey: ${{ secrets.ANDROID_SIGNING_KEY }} | |
keyAlias: ${{ secrets.ANDROID_KEY_ALIAS }} | |
keyStorePassword: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} | |
keyPassword: ${{ secrets.ANDROID_KEY_PASSWORD }} | |
- name: Build Changelog | |
if: ${{ steps.regex-match.outputs.match != '' }} | |
id: changelog | |
uses: ardalanamini/auto-changelog@v3 | |
with: | |
mention-authors: false | |
mention-new-contributors: false | |
include-compare: false | |
semver: false | |
- name: Create Release | |
if: ${{ steps.regex-match.outputs.match != '' }} | |
id: create_release | |
uses: ncipollo/release-action@v1.13.0 | |
with: | |
artifacts: "app/build/outputs/app-release-signed.aab, app/build/outputs/app-release-signed.apk" | |
body: ${{ steps.changelog.outputs.changelog }} | |
tag: ${{ github.event.head_commit.message }} | |
name: Release ${{ github.event.head_commit.message }} | |
token: ${{ secrets.GITHUB_TOKEN }} |
You are now good to go. So anytime you create a tag and push the tag to GitHub, the actions is going to build apk and aab files, sign them, make artifacts, create a release with the tag, upload the files in the release as assets.
Here’s an example project of the above usage:
GitamTransit
Want to use GitHub secrets in your Android Apps? Check out this post.
Top comments (4)
Hi, many thanks!
Regarding 'signingKeyBase64' - is the key and keystore the same thing (format)?
I already have my android keystore into Github secrets and it works nice for signing 3D Unity apps, but when I tried to use it in r0adkll/sign-android-release@v1, I received "Failed to load signer "signer #1"
java.io.EOFException" exception.
Hey @vitalykarasik , I've found out the solution in issues.
Check out this link for the solution.
Hi
I did exactly same but I got this error:
Execution failed for task ':app:validateSigningRelease'.
I know 'my-upload-key.keystore' is not uploaded to my repository, but the questions is why it needs this file while I've already import the key base64 content in the action secret?
Solution:
stackoverflow.com/questions/730242...