Skip to content

Instantly share code, notes, and snippets.

@dkarmalita
Last active August 27, 2022 00:26
Show Gist options
  • Save dkarmalita/b2bb12ec41bde7ce9cfb56e964101945 to your computer and use it in GitHub Desktop.
Save dkarmalita/b2bb12ec41bde7ce9cfb56e964101945 to your computer and use it in GitHub Desktop.
Android SDK & Emulator installer for React Native development
#! /bin/bash
# =================================
# Android SDK & Emulator installer
# For React Native development
# Platform: OSX, WIN
# Ver: 20171128
# [email protected]
# Original gist: https://git.io/vbLFg
# =================================
#
# Usage:
# ------
# bash <(curl -s -L https://git.io/vbLx6)
#
# Change Log:
# -----------
# Ver: 20171115
# + [FEATURE] Confirmation dialog
# + [FEATURE] Windows support
#
# Ver: 20171108
# ~ [FIX] .bash_profile is adressed with $HOME
#
# Ver: 20171101
# + [INITIAL] Initial Version
clear
echo "#####################################################################################"
echo "# This sctipt is going to install Android SDK & Emulator for React Native development"
echo "# to \"$(pwd)\" directory"
echo -n "Should it proceed (y/n)? "
read answer
if echo "$answer" | grep -iq "^y" ; then
echo ''
else
exit 0
fi
set -e
RUNEMULATOR_URL="https://www.dropbox.com/s/24qur0u1qtb5a05/run-emulator.zip?dl=0"
SKIN_URL="https://github.com/markusherzog/android-emulator-skin-nexus-5/archive/master.zip"
ANDROID_SDK_HOME=$(pwd)
ANDROID_HOME=$ANDROID_SDK_HOME/sdk
export ANDROID_SDK_HOME ANDROID_HOME
TMP_DIR=$(pwd)
case "$OSTYPE" in
darwin*)
echo "=> OSX detected"
ANDROID_SDK_LIC="\nd56f5187479451eabf01fb78af6dfcb131a6481e"
ANDROID_SDK_PREVIEW_LIC="\n84831b9409646a918e30573bab4c9c91346d8abd"
ANDROID_TOOLS_URL="https://dl.google.com/android/repository/sdk-tools-darwin-3859397.zip"
AVDMANAGER=$ANDROID_HOME/tools/bin/avdmanager
SDKMANAGER=$ANDROID_HOME/tools/bin/sdkmanager
;;
msys*)
echo "=> WINDOWS detected"
ANDROID_SDK_LIC="\nd56f5187479451eabf01fb78af6dfcb131a6481e"
ANDROID_SDK_PREVIEW_LIC="\n504667f4c0de7af1a06de9f4b1727b84351f2910"
ANDROID_TOOLS_URL="https://dl.google.com/android/repository/sdk-tools-windows-3859397.zip"
AVDMANAGER=$ANDROID_HOME/tools/bin/avdmanager.bat
SDKMANAGER=$ANDROID_HOME/tools/bin/sdkmanager.bat
echo '=> Generating debug key (win)'
mkdir -p $ANDROID_SDK_HOME/.android
keytool -genkey -v -keystore $ANDROID_SDK_HOME/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" -keyalg RSA -keysize 2048 -validity 10000
;;
*)
echo "Unsupported OS: $OSTYPE"
exit -1
;;
esac
echo '=> Install basic Android tools'
curl -L $ANDROID_TOOLS_URL -o $TMP_DIR/tools.zip
unzip -oq $TMP_DIR/tools.zip -d $ANDROID_HOME
rm -rf $TMP_DIR/tools.zip
mkdir -p $ANDROID_SDK_HOME/.android
touch $ANDROID_SDK_HOME/.android/repositories.cfg
echo '=> Install licences'
mkdir $ANDROID_HOME/licenses
echo -ne $ANDROID_SDK_LIC >> $ANDROID_HOME/licenses/android-sdk-license
echo -ne $ANDROID_SDK_PREVIEW_LIC >> $ANDROID_HOME/licenses/android-sdk-preview-license
echo '=> Instal React-Native dependensies'
${SDKMANAGER} --verbose 'build-tools;23.0.1' 'add-ons;addon-google_apis-google-23' 'platforms;android-23'
echo "=> NDK (remove if you don't need it)"
${SDKMANAGER} --verbose 'ndk-bundle'
echo '=> Install emulator & dependensies'
#echo y |
${SDKMANAGER} --verbose 'emulator'
${SDKMANAGER} --verbose 'platform-tools' 'system-images;android-26;google_apis;x86'
echo '=> Load nexus_5x skin'
mkdir -p $ANDROID_HOME/skins
curl -L $SKIN_URL -o $TMP_DIR/skin.zip
unzip -ojq $TMP_DIR/skin.zip -d $ANDROID_HOME/skins/nexus_5x
rm -rf $TMP_DIR/skin.zip
echo '=> Creating Nexus_5X AVD'
${AVDMANAGER} --verbose create avd --force --name "Nexus_5X" --device "Nexus 5X" --package "system-images;android-26;google_apis;x86" --tag "google_apis" --abi "x86"
echo '=> Add skin reference to Nexus_5X AVD'
echo 'skin.name=nexus_5x' >>$ANDROID_SDK_HOME/.android/avd/Nexus_5X.avd/config.ini
echo 'skin.path=skins/nexus_5x' >>$ANDROID_SDK_HOME/.android/avd/Nexus_5X.avd/config.ini
echo '=> Install run-emulator script'
curl -L $RUNEMULATOR_URL -o $TMP_DIR/run-emulator.zip
unzip -oq $TMP_DIR/run-emulator.zip -d $ANDROID_SDK_HOME
rm -rf $TMP_DIR/run-emulator.zip
echo '=> Create envirament variables'
echo ''>>$HOME/.bash_profile
echo '# Android SDK references'>>$HOME/.bash_profile
echo '# ----------------------'>>$HOME/.bash_profile
echo "ANDROID_HOME=$ANDROID_HOME">>$HOME/.bash_profile
echo "ANDROID_SDK_HOME=$ANDROID_SDK_HOME">>$HOME/.bash_profile
echo 'ANDROID_NDK=$ANDROID_HOME/ndk-bundle'>>$HOME/.bash_profile
echo 'PATH=$ANDROID_HOME/platform-tools:$PATH'>>$HOME/.bash_profile
# Note: The line above creates minimal PATH extension, to make it more comfortable, use the full tool's exposure with
# echo 'PATH=$ANDROID_SDK_HOME:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/bin:$PATH'>>$HOME/.bash_profile
echo 'export ANDROID_SDK_HOME ANDROID_HOME ANDROID_NDK PATH'>>$HOME/.bash_profile
echo [DONE]
echo ''
echo 'Now you can run Android Emulator with following commands:'
echo '$ANDROID_SDK_HOME/run-emulator'
echo '$ANDROID_HOME/emulator/emulator -avd Nexus_5X'
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment