Configuring a headless build system for Android

When developing apps for Android, I use Android Studio which provides all the aspiring developer needs to get something working. In the past, I've developed and published an app on Google Play where there was no specific build system and new development and release build were the same machine because it was quick and easy. It did require some careful juggling if I needed to make a hotfix to a release build while previously working on a development version. Version control software, like Git, makes this easier, and this combined development and build environment sat uneasily with me given my enterprise development & support background where build systems were considered sacred since our ability to deliver fixes to clients depended on them. So when I started putting together Controller for Mote, I decided I would take the opportunity to set up a dedicated Android build system on an old spare system I had laying idle.

Before beginning, I installed Ubuntu 16.04 LTS Server onto my build system to be. In my case, the system is Intel Atom D525 based, with a nVidia ION chipset and 4GB of RAM. It has (courtesy of a previous use) a 120GB SSD drive. This is not a particularly high spec'd system and it doesn't need to be - local test builds for development will still happen on my local workstation. Regular builds for test and release can be kicked off as required using Jenkins, which I'll cover in a future post.

So assuming you have your base system installed and on the network.

  1. Install OpenJDK 8. This is now required for API 24  (Nougat) and is provided with Android Studio.

    sudo apt-get update
    sudo apt-get install openjdk-8-jdk

  2. You can also install additional packages:

    sudo apt-get install libc6:i386 libstdc++6:i386
    sudo apt-get install zlib1g:i386

  3. Download and extract the latest Android SDK. An example is provided below (correct at time of writing). You can find the correct version by heading to the Andrord Studio page, scrolling to near the end, and right clicking the link for the Linux command line tools. Depending on your browser, you should then be able to copy the link.

    tar -xvf android-sdk_r24.4.1-linux.tgz

  4. Install the SDK packages using the no-gui option. Note, depending on where you want the SDK to live, you need to set permissions and/or use sudo as appropriate.

    cd android-sdk-linux/tools/
    sudo ./android update sdk --no-ui

  5. Add the JAVA_HOME and ANDROID_HOME environment variables to your environment as appropriate. In my case, I chose to use the /etc/environment file to make the changes system wide.


  6. Assuming your source is already on the system (or you pull it if not), run your build

     ./gradlew assembleDebug

That should be all that is required.

The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top