Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Shell script to check for Android SDK version.
# Bash script to assert that the current version of the SDK is at least the
# specified version. Prints 'true' to standard out if it's the right version,
# 'false' if it's not.
# Typically used like this, in your Makefile:
# ifneq ($(shell $(LOCAL_PATH)/ "r16"),true)
# $(error SDK version r16 or greater required)
# endif
# See for asserting NDK version.
# Copyright 2012, Lookout, Inc. <>
# Converts 'r16' into '16'.
function get_version() {
echo "$1" | sed s/^r//
if [[ -z "$1" ]]; then
echo "Usage: $0 <required version>" >&2
echo " For example: $0 r16" >&2
exit 1
expected_version=$(get_version "$1")
emulator_path="$(which emulator)"
if [ ! -z "$emulator_path" ]; then
ANDROID_SDK_ROOT="$(dirname "$emulator_path")/.."
elif [ -z "$ANDROID_SDK_ROOT" ]; then
echo "Could not find location of SDK. Put 'emulator' in \$PATH or set \$ANDROID_SDK_ROOT." >&2
echo false
exit 1
if [ ! -s "$source_props" ]; then
echo "Assumed SDK path '$ANDROID_SDK_ROOT', could not find tools/" >&2
echo false
exit 1
# Make sure the data is at least kinda sane.
version=$(grep -i '^Pkg.Revision=' $source_props | cut -f2- -d=)
actual_version=$(get_version "$version")
if [ -z "$version" ] || [ -z "$actual_version" ]; then
echo "Invalid tools/ $(cat $source_props)" >&2
echo false
exit 1
# Unlike the NDK version, SDK versions seem to always be a number, so
# we're just doing a numerical comparison.
if [[ $actual_version -lt $expected_version ]]; then
echo "false"
echo "true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment