1*25039b37SCy Schubert#!/usr/bin/env bash 2*25039b37SCy Schubert 3*25039b37SCy Schubertif [ -z "$ANDROID_SDK_ROOT" ]; then 4*25039b37SCy Schubert echo "ERROR: ANDROID_SDK_ROOT is not a valid path. Please set it." 5*25039b37SCy Schubert echo "SDK root is $ANDROID_SDK_ROOT" 6*25039b37SCy Schubert exit 1 7*25039b37SCy Schubertfi 8*25039b37SCy Schubert 9*25039b37SCy Schubertif [ -z "$ANDROID_NDK_ROOT" ]; then 10*25039b37SCy Schubert echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." 11*25039b37SCy Schubert echo "NDK root is $ANDROID_NDK_ROOT" 12*25039b37SCy Schubert exit 1 13*25039b37SCy Schubertfi 14*25039b37SCy Schubert 15*25039b37SCy Schubertecho "Using ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT" 16*25039b37SCy Schubertecho "Using ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT" 17*25039b37SCy Schubert 18*25039b37SCy Schubertecho "Downloading SDK" 19*25039b37SCy Schubertif ! curl -L -k -s -o "$HOME/android-sdk.zip" https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip; 20*25039b37SCy Schubertthen 21*25039b37SCy Schubert echo "Failed to download SDK" 22*25039b37SCy Schubert exit 1 23*25039b37SCy Schubertfi 24*25039b37SCy Schubert 25*25039b37SCy Schubertecho "Downloading NDK" 26*25039b37SCy Schubertif ! curl -L -k -s -o "$HOME/android-ndk.zip" https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip; 27*25039b37SCy Schubertthen 28*25039b37SCy Schubert echo "Failed to download NDK" 29*25039b37SCy Schubert exit 1 30*25039b37SCy Schubertfi 31*25039b37SCy Schubert 32*25039b37SCy Schubertecho "Unpacking SDK to $ANDROID_SDK_ROOT" 33*25039b37SCy Schubertif ! unzip -qq "$HOME/android-sdk.zip" -d "$ANDROID_SDK_ROOT"; 34*25039b37SCy Schubertthen 35*25039b37SCy Schubert echo "Failed to unpack SDK" 36*25039b37SCy Schubert exit 1 37*25039b37SCy Schubertfi 38*25039b37SCy Schubert 39*25039b37SCy Schubertecho "Unpacking NDK to $ANDROID_NDK_ROOT" 40*25039b37SCy Schubertif ! unzip -qq "$HOME/android-ndk.zip" -d "$HOME"; 41*25039b37SCy Schubertthen 42*25039b37SCy Schubert echo "Failed to unpack NDK" 43*25039b37SCy Schubert exit 1 44*25039b37SCy Schubertfi 45*25039b37SCy Schubert 46*25039b37SCy Schubertif ! mv "$HOME/android-ndk-r20b" "$ANDROID_NDK_ROOT"; 47*25039b37SCy Schubertthen 48*25039b37SCy Schubert echo "Failed to move $HOME/android-ndk-r20b to $ANDROID_NDK_ROOT" 49*25039b37SCy Schubert exit 1 50*25039b37SCy Schubertfi 51*25039b37SCy Schubert 52*25039b37SCy Schubertrm -f "$HOME/android-sdk.zip" 53*25039b37SCy Schubertrm -f "$HOME/android-ndk.zip" 54*25039b37SCy Schubert 55*25039b37SCy Schubert# https://stackoverflow.com/a/47028911/608639 56*25039b37SCy Schuberttouch "$ANDROID_SDK_ROOT/repositories.cfg" 57*25039b37SCy Schubert 58*25039b37SCy Schubertecho "Finished installing SDK and NDK" 59*25039b37SCy Schubert 60*25039b37SCy Schubertexit 0 61