Android Remote build

Aron
2 min readApr 7, 2023

Challenge

Clean building of any Android project can be a time-consuming process, and ours is no exception. If your project has a long history and has a multimodule approach then it might take a few minutes to even an hour to complete.

Possible options

  • Optimize gradle tasks

Optimizing Gradle can take you a long way, but you might also find that you outgrow it at some point

  • Move gradle executions to a remote machine

Mainframer is a tool based on rsync that offers you two ways of synching between your local machine and a remote one.You end up trading compilation time for transfer time: If the remote machine is powerful enough, your main bottleneck will be transferring your source code and moving binaries back and forth from the remote machine.

  • Change build system to Bazel

Bazel has been used internally by Google to build the majority of their apps, and it supports projects with multiple languages and build targets. Because it was specifically designed to support large codebases running across multiple repositories, and with many contributors, it is inherently more scalable than Gradle. But Bazel can solve large monorepo build problems very well, but it has a steep adoption curve, so we thought of giving it a try later and skip for now

Solution

We used Mirakle which is is a fork of the Mainframer project modified to work with Gradle build systems. It’s a Gradle plugin and makes everything happening behind the scenes totally invisible to the upper layers.

What does that mean? Android Studio won’t notice you’re compiling your code on another computer so you can continue working with your IDE as usual.

Below are the series of steps we used to configure Mirakle for our remote build

  • Execute the below script to enable remote build enable.sh
enable.sh
  • Execute the below script to disable remote build disable.sh
disable.sh

The numbers

The performance improvement isn’t just the time improvement, we use 16GB RAM laptops to develop and we were having a lot of issues with RAM usage, making our machines very laggy while compiling.

Conclusions

High compile times are one of the most distracting processes a developer faces. And complex Android projects based on Gradle use to be slow. So we should care about compile time, not only to speed up the development process, but also improve our experience, avoiding distracting and stressful compilations of several minutes.

--

--