Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env sh
- USER_SHELL="$HOME/.zshrc"
- TIMEZONE="Canada/Mountain"
- AVD_DEVICE="Nexus 5X" # replace with your prefered device from 'avdmanager list device'
- get_timezone() {
- PS3="Choose your timezone: "
- options=("Mountain" "Pacific")
- select opt in "${options[@]}"
- do
- case $opt in
- "Mountain")
- TIMEZONE="Canada/Mountain"
- break
- ;;
- "Pacific")
- TIMEZONE="Canada/Pacific"
- break
- ;;
- *) echo invalid option;;
- esac
- done
- }
- get_shell() {
- PS3="Choose your shell: "
- options=("Zsh" "Bash")
- select opt in "${options[@]}"
- do
- case $opt in
- "Zsh")
- USER_SHELL="$HOME/.zshrc"
- break
- ;;
- "Bash")
- USER_SHELL="$HOME/.bash_profile"
- break
- ;;
- *) echo invalid option;;
- esac
- done
- }
- setup_android_emulator(){
- AVD_NAME=$1
- AVD_TARGET=$2
- echo "\nCreating AVD image $AVD_NAME"
- avdmanager create avd -c 64M -n $AVD_NAME -d "${AVD_DEVICE}" -k $AVD_TARGET
- echo "hw.keyboard=yes" >> $HOME/.android/avd/$AVD_NAME\.avd/config.ini
- }
- get_timezone
- echo
- get_shell
- # =======================
- # install Java8 and Android SDK
- echo "\nInstalling Java8"
- brew cask install caskroom/versions/java8
- echo "\nInstalling Android SDK"
- brew cask install android-sdk
- # =======================
- # export shell path to work with Android
- echo "\n# Android PATHs" >> $USER_SHELL
- echo 'export ANDROID_HOME="/usr/local/share/android-sdk"' >> $USER_SHELL
- echo 'export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin/:$PATH"' >> $USER_SHELL
- # create a function to easily start the emulator from the shell
- echo '\n# pass the parameter to be one of the created images api21, api24, api25, api26, or api27
- function startEmulator() { emulator -timezone '$TIMEZONE' -noaudio -no-boot-anim -memory 256 -avd $1& }' >> $USER_SHELL
- ANDROID_HOME="/usr/local/share/android-sdk"
- PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin/:$PATH"
- # =======================
- # install Android tools
- yes | sdkmanager --licenses
- echo "\nInstalling Android SDK"
- sdkmanager --verbose "build-tools;27.0.3" \
- "docs" \
- "emulator" \
- "tools" \
- "extras;android;gapid;3" \
- "extras;android;m2repository" \
- "extras;google;google_play_services" \
- "extras;google;m2repository" \
- "extras;intel;Hardware_Accelerated_Execution_Manager" \
- "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2" \
- "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" \
- "patcher;v4" \
- "platform-tools" \
- "platforms;android-21" \
- "platforms;android-22" \
- "platforms;android-23" \
- "platforms;android-24" \
- "platforms;android-25" \
- "platforms;android-26" \
- "platforms;android-27" \
- "system-images;android-21;default;x86_64" \
- "system-images;android-24;default;x86_64" \
- "system-images;android-25;google_apis;x86" \
- "system-images;android-26;google_apis;x86_64" \
- "system-images;android-27;google_apis;x86"
- echo "\nUpdating Android SDK"
- sdkmanager --update
- # =======================
- # install Intel HAXM
- echo "\nEnter your admin password to silently install Intel Accelerated Execution Manager kernel extension" \
- && sudo sh /usr/local/share/android-sdk/extras/intel/Hardware_Accelerated_Execution_Manager/silent_install.sh
- # =======================
- # Create a few AVDs
- # -d specified the device you'd like to use, choose and replace with your prefered device from 'avdmanager list device'
- echo "\nCreating AVD image for API 21"
- setup_android_emulator "api21" "system-images;android-21;default;x86_64"
- echo "\nCreating AVD image for API 24"
- setup_android_emulator "api24" "system-images;android-24;default;x86_64"
- echo "\nCreating AVD image for API 25"
- setup_android_emulator "api25" "system-images;android-25;google_apis;x86"
- echo "\nCreating AVD image for API 26"
- setup_android_emulator "api26" "system-images;android-26;google_apis;x86_64"
- echo "\nCreating AVD image for API 27"
- setup_android_emulator "api27" "system-images;android-27;google_apis;x86"
- # =======================
- # For some reason Android complains if this file is missing, touch it.
- touch $HOME/.android/repositories.cfg
- echo "\nInstallation successful, restart your shell"
Add Comment
Please, Sign In to add comment