Search code examples
androidbuildandroid-gradle-plugincloudandroid-studio-2.0

Build local gradle app on remote server in Android Studio


The size of my current project including the dependencies is growing all the time, which means right now it takes around 2 minutes on my local machine to create the current gradle build.

We already have a CI system which is building on pushes, but is there also a way to use cloud-resources to build the local version and pull it back to the local machine for testing and debugging in the emulator or a connected device?

Yes a solution would be to buy a faster PC, but that doesn't really scale well as also our engineering team is growing all the time. So renting a cloudserver, which is doing the heavy CPU work would be a very economical option.


Solution

    1. We can use mainframer or Mirakle to move the build process to remote machine. Check this article for more detail. We can run Docker container in remote-machine along with mainframer. Check this.

    The basic principle upon which they both operate is that they open an SSH connection to the build executor, perform an rsync of your development folder to copy across any changes (such as edited source files) to the executor, run the build, and then perform a second rsync to copy the changes (including the compiled APK) back to your development machine.

    1. We can take advantage of Gradle build-cache server. Gradle is using the build cache since November 2016 and saw a median build time reduction of 15%. Check this and this for more information.

    The recommended setup for the build cache is that your continuous integration server populates the remote build cache with the artifacts of clean builds. Developers will just pull from the remote cache and push to a local build cache.

    Hope this will help future users.