Installing the Android SDK on a headless server doesn’t seem to be very well documented. I recently needed to do this to get the SDK installed on a TeamCity build agent to automate Android builds and tests.
Below are some simple instructions to help you along the way. I’m using a Mac, so you may need to use slightly different commands if you’re using Linux.
Step 1: Download the Android SDK onto the box
$ curl -C - -O http://dl.google.com/android/android-sdk_r16-macosx.zip
Step 2: Unzip the SDK
I decided to put the SDK in my /Applications directory. You can put it wherever you want, but if you want to follow my lead you can use the following commands to get it into the /Applications dir:
$ mv android-sdk_r16-macosx.zip /Applications $ cd /Applications $ unzip android-sdk_r16-macosx.zip
Step 3: Determine what API levels, tools, and documentation you want to install
You now have a base SDK installed, but you still need to download the corresponding Android APIs for whichever Android version you’re developing for. In order to know what you need to install, you’ll want to list the available APIs, tools, and docs. We can use the android tool to do this and the –no-ui flag to alert the tool that we’re on the command line. Here is how to get a list of what’s available:
$ cd /Applications/android-sdk-macosx $ tools/android list sdk --no-ui Refresh Sources: Fetching https://dl-ssl.google.com/android/repository/addons_list-1.xml Validate XML Parse XML ...snip... Packages available for installation or update: 61 1- Documentation for Android SDK, API 15, revision 1 2- SDK Platform Android 4.0.3, API 15, revision 2 3- SDK Platform Android 4.0, API 14, revision 3 4- SDK Platform Android 3.2, API 13, revision 1 5- SDK Platform Android 3.1, API 12, revision 3 6- SDK Platform Android 3.0, API 11, revision 2 7- SDK Platform Android 2.3.3, API 10, revision 2 8- SDK Platform Android 2.2, API 8, revision 3 9- SDK Platform Android 2.1, API 7, revision 3 10- SDK Platform Android 1.6, API 4, revision 3 11- SDK Platform Android 1.5, API 3, revision 4 ...snip... 56- Android Support package, revision 6 57- Google Admob Ads Sdk package, revision 4 58- Google Analytics Sdk package, revision 2 59- Google Market Billing package, revision 1 60- Google Market Licensing package, revision 1 61- Google Webdriver package, revision 2
Step 4: Install your packages
Ok, so you have a list of the APIs and tools. See which ones you want to install and find their corresponding number. If you want to install API 15 and the Android Support package, you’ll want number 2 and 56. We can use the android tool again and the –filter flag to alert it that we only want to install package 2 and 56:
$ tools/android update sdk --filter 2,56 --no-ui
Happy hacking Android devs!