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 builds.sr.ht. Here is how to setup build.sr.ht 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 sr.ht 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 sr.ht 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 sr.ht 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
packages:
  - gradle
  - rsync
# The sr.ht git repo that contains my application. Enter your own app's git repo here
sources:
  - https://git.sr.ht/~anjan/lift
environment:
  deploy: deploy@momi.ca
secrets:
# 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
triggers:
  - action: email
    condition: failure
    to: Anjandev Momi <anjan@momi.ca>
tasks:
  - 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 sr.ht. 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 sr.ht 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 sr.ht - use a different git host. The documentation for fdroid's build tools are here: f-droid: publishing nightly builds

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

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

Articles from blogs I follow around the net

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

A few ways to make money in FOSS

I work on free and open-source software full time, and I make a comfortable living doing it. And I don’t half-ass it: 100% of my code is free and open-source. There’s no proprietary add-ons, no periodic code dumps, just 100% bona-fide free and open source so…

via Drew DeVault's blog November 20, 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