[Android] Align deps target API level with one chosen at makefile

Signed-off-by: Anestis Bechtsoudis <anestis@census-labs.com>
diff --git a/third_party/android/scripts/compile-capstone.sh b/third_party/android/scripts/compile-capstone.sh
index 452f973..a6ddee5 100755
--- a/third_party/android/scripts/compile-capstone.sh
+++ b/third_party/android/scripts/compile-capstone.sh
@@ -15,6 +15,9 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
+set -e # fail on unhandled error
+#set -x # debug
+
 abort() {
   cd - &>/dev/null
   exit "$1"
@@ -29,7 +32,7 @@
   exit 1
 fi
 
-readonly CAPSTONE_DIR=$1
+readonly CAPSTONE_DIR="$1"
 
 if [ ! -d "$CAPSTONE_DIR/.git" ]; then
   git submodule update --init third_party/android/capstone || {
@@ -117,11 +120,15 @@
   fi
 fi
 
+if [ -z "$ANDROID_API" ]; then
+  ANDROID_API="android-21"
+fi
+
 # Support both Linux & Darwin
 HOST_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
 HOST_ARCH=$(uname -m)
 
-SYSROOT="$NDK/platforms/android-21/arch-$ARCH"
+SYSROOT="$NDK/platforms/$ANDROID_API/arch-$ARCH"
 export CC="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-gcc --sysroot=$SYSROOT"
 export CXX="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-g++ --sysroot=$SYSROOT"
 export PATH="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin":$PATH
diff --git a/third_party/android/scripts/compile-libBlocksRuntime.sh b/third_party/android/scripts/compile-libBlocksRuntime.sh
index f854fb5..b263a20 100755
--- a/third_party/android/scripts/compile-libBlocksRuntime.sh
+++ b/third_party/android/scripts/compile-libBlocksRuntime.sh
@@ -15,8 +15,6 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-readonly ANDROID_API="android-23"
-
 if [ -z "$NDK" ]; then
   # Search in $PATH
   if [[ $(which ndk-build) != "" ]]; then
@@ -27,6 +25,10 @@
   fi
 fi
 
+if [ -z "$ANDROID_API" ]; then
+  ANDROID_API="android-23"
+fi
+
 if [ $# -ne 2 ]; then
   echo "[-] Invalid arguments"
   echo "[!] $0 <libBlocksRuntime_DIR> <ARCH>"
@@ -34,7 +36,7 @@
   exit 1
 fi
 
-readonly BRT_DIR=$1
+readonly BRT_DIR="$1"
 
 case "$2" in
   arm|arm64|x86|x86_64)
diff --git a/third_party/android/scripts/compile-libunwind.sh b/third_party/android/scripts/compile-libunwind.sh
index 55eba55..9c04501 100755
--- a/third_party/android/scripts/compile-libunwind.sh
+++ b/third_party/android/scripts/compile-libunwind.sh
@@ -15,6 +15,7 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
+set -e # fail on unhandled error
 #set -x # debug
 
 abort() {
@@ -83,6 +84,10 @@
   fi
 fi
 
+if [ -z "$ANDROID_API" ]; then
+  ANDROID_API="android-21"
+fi
+
 case "$2" in
   arm|arm64|x86|x86_64)
     readonly ARCH="$2"
@@ -180,7 +185,7 @@
 HOST_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
 HOST_ARCH=$(uname -m)
 
-SYSROOT="$NDK/platforms/android-21/arch-$ARCH"
+SYSROOT="$NDK/platforms/$ANDROID_API/arch-$ARCH"
 export CC="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-gcc --sysroot=$SYSROOT"
 export CXX="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-g++ --sysroot=$SYSROOT"
 export PATH="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin":$PATH