Created
June 5, 2012 23:27
-
-
Save jorgenpt/2878774 to your computer and use it in GitHub Desktop.
Shell script to check for Android SDK version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 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)/assert_sdk_version.sh "r16"),true) | |
# $(error SDK version r16 or greater required) | |
# endif | |
# | |
# See https://gist.github.com/1961404 for asserting NDK version. | |
# | |
# Copyright 2012, Lookout, Inc. <[email protected]> | |
# 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 | |
fi | |
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 | |
fi | |
source_props="$ANDROID_SDK_ROOT/tools/source.properties" | |
if [ ! -s "$source_props" ]; then | |
echo "Assumed SDK path '$ANDROID_SDK_ROOT', could not find tools/source.properties." >&2 | |
echo false | |
exit 1 | |
fi | |
# 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/source.properties: $(cat $source_props)" >&2 | |
echo false | |
exit 1 | |
fi | |
# 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" | |
else | |
echo "true" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment