Build Android in the Cloud
In this example, you are given a task to build Android app on a 64-bit AWS Linux build agent running in Amazon Cloud (AWS).
Install Android SDK
You have to start with installing Android SDK first.
Start with downloading latest Linux version, found on this page. You can find direct link to tarball in “DOWNLOAD FOR OTHER PLATFORMS” section.
Extract and Move
Extract it and put in preferred location, in this example it’s
ANDROID_HOME and update the path. That is done by modifying
~/.bash_profile, create the file if you don’t have it yet.
You noticed that adding Android Build Tools to the path is optional. That’s because we didn’t install Build Tools yet.
Update Android SDK
This is where you update Android SDK, install all the tools and APIs, including Build Tools and Android Support Repository and Library. Remember, this Linux instance is running in the AWS Cloud meaning it’s headless (no GUI) and you only can work with the shell.
If you happened to read older version of this article, you’d remember seeing a lot of shell scripts using
This is a revised version, with much simpler and cleaner code.
The command that does the job is
android update sdk. You need to use
--filter option to specify list of packages you need to update or install. To get readable identifiers of all available packages, run the following command
--extended flag is used to display extended information about each package, including a human readable identifier.
--all is needed to include extra packages, like build tools, by default they won’t be listed. Here’s an example output.
You can now compose filter as a comma-separated list of all package identifiers you want to install. Since it’s a headless build box, you will have to use
--no-ui option, and
--all is needed to include extra packages.
This example installs Android SDK Tools, Platform tools, Build tools versions 20.0.0 and 19.0.1, as well as SDK Platform 19 and 20. Customize the list to your needs using proper identifiers.
Answering the Prompts
But it’s not done yet. When installing or updating, you will have to accept license prompts. Each package can have it’s own license requiring you to answer a prompt with “y”.
You’d probably think of
yes command line utility designed for this particular task. However it will not work.
yes outputs “y” to stdout too often with no options to put delays in between. Android SDK update tool expects not just “y”, but a “y” followed by return key, in other words, it expects “y\n” string as a whole. I don’t know the exact mechanics of
yes command, but if you try something like this
you will see that the license prompt will complain about incorrect input and fail after a number of attempts.
The solution is to put certain delay between “y” outputs to stdout. This code I found on the web, it’s reliable and does the job.
Project Specific SDK Update
If you have various Android projects, each with it’s own requirements for Android packages, it would be reasonable to add Android SDK update task to the project’s build configuration. In this example I will use Gradle, so here’s an example of Gradle task
The last and very annoying bit, is that this script seems to update packages even if they are already installed. At the moment I have no clue what’s causing this behavior and what’s the best workaround. When it comes to running this script on one of the Bamboo agents in the cloud it doesn’t really matter, but when the script runs on one and only Mac build agent you have - this really slows down each build.
Install 32-bit Libraries
Before you try to build anything, you have to do one more thing.
Remember, the host OS is 64-bit Linux system. Android requires a bunch of 32-bit libraries and you have to install them. The Linux system in question is RPM-based so this example uses
yum command, change it to
apt-get or another package manager specific for your OS.
Now you’re good to go!
This is a TLDR or a summary section, that simply lists the solution “as is”.
blog comments powered by Disqus