Sourcehut Android Gradle Continuous Integration

Published 2019-11-14 on Anjan's Homepage

1 Introduction to Sourcehut

Sourcehut is my git hosting platform of choice. Sourcehut offers a continious integration platform called Here is how to setup to compile android projects with gradle.

2 Secrets

Before we begin, we need to create the android-sdk-license build secret. This file will tell the android build service (gradle in this guide) that you have agreed to all the required licenses for the dependancies upon which your project depends.

If you have built your android apps on your pc, you already have this file and are ready to go. Open up build secrets. Select Secret Type: File and enter the following details for your new secret:

Name: androidLicense

Path:  ~/android/licenses/android-sdk-license

Mode: 644

Click browse and navigate to where you have installed the android sdk on your local machine. Upload the file called android-sdk-license in the folder licenses.

Finally, in build secrets, click Add Secret.

On the right pane, a new secret should appear. There should be a UUID that represents the license file you just uploaded. When you include this UUID in your build manifest, android-sdk-license will be copied to the correct folder in your build environment.

If you would like to send your built apks to a vps, make sure you add your ssh config (nonstandard ports) and a new ssh private key to your secrets.

3 .build.yml

Finally, we have to make the .build.yml file on the root of your git repository on your local machine. You can use to lint and check whether your app will build on a clean machine with the latest version of gradle (build). I take it one step further and upload my unsigned build to my vps (deploy). This creates fresh unsigned builds for the latest commit of my app.

Here is my .build.yml from my own project lift: a free software workout app.

# I use archlinux for my image because I want to test whether my app
# builds with the latest release of gradle. Features are often deprecated on
# android and I did not know that my app was using alot of deprecated features
# until I tried to build with the latest version of gradle.
image: archlinux
  - gradle
  - rsync
# The git repo that contains my application. Enter your own app's git repo here
# UUIDs for ssh and android license secrets
  - 88e37d5a-6a50-4a14-b9d5-a944dc17bf50
  - b0ee6bc9-84d5-4962-a8cb-fc0a9e002bfa
  - 336f1246-50a2-464a-b3fe-1b54cba37a45
# Tell builds to send me an email if the build fails
  - action: email
    condition: failure
    to: Anjandev Momi <>
  - build: |
      export ANDROID_SDK_ROOT=~/android
      cd lift
      gradle assemble
  - deploy: |
      cd lift/app/build/outputs/apk/debug
      sshopts="-o StrictHostKeyChecking=no"
      rsync --rsh="ssh $sshopts" -rP . ${deploy}:/srv/http/android/android

Finally, add this file in git, commit, and push to Your build should begin!

4 Installing the rsynced app

Be advised, you will not be able to install the apk that is rsynced by your .build.yml until you sign it using something like jarsigner. I do not sign my latest commit builds because they are strictly for myself.

You could generate a keystore using jarsigner, upload it as a secret to build secrets, and then add a couple extra lines before rsyncing to sign the app using jarsigner. However, I would prefer to use fdroid's build tools at that point. Please do not store large files on - use a different git host. The documentation for fdroid's build tools are here: f-droid: publishing nightly builds

When supports large files, I will write a blog post about using f-droid build tools on

Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~anjan/ [mailing list etiquette]

Articles from blogs I follow around the net

These articles/blogs do not represent my own opinions or views.

Web analytics should at least meet the standards of informed consent

Research conducted on human beings, at least outside of the domain of technology, has to meet a minimum standard of ethical reasoning called informed consent. Details vary, but the general elements of informed consent are: Disclosure of the nature and purpose…

via Drew DeVault's blog December 4, 2020

How to Make Biomass Energy Sustainable Again

From the Neolithic to the beginning of the twentieth century, coppiced woodlands, pollarded trees, and hedgerows provided people with a sustainable supply of energy, materials, and food.

via LOW←TECH MAGAZINE September 20, 2020

Eshell versus M-x shell

I’ve used and defended Eshell for years. Sadly, Eshell has some long standing issues that I grew tired of in the long run. So I’ve decided to switch to M-x shell and see how much of my Eshell workflow I could port. Language and the underlying shell pr…

via Pierre Neidhardt's homepage June 26, 2020

Generated by openring