Guest User

Untitled

a guest
Feb 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. #!/usr/bin/env sh
  2.  
  3. USER_SHELL="$HOME/.zshrc"
  4. TIMEZONE="Canada/Mountain"
  5. AVD_DEVICE="Nexus 5X" # replace with your prefered device from 'avdmanager list device'
  6.  
  7. get_timezone() {
  8. PS3="Choose your timezone: "
  9. options=("Mountain" "Pacific")
  10. select opt in "${options[@]}"
  11. do
  12. case $opt in
  13. "Mountain")
  14. TIMEZONE="Canada/Mountain"
  15. break
  16. ;;
  17. "Pacific")
  18. TIMEZONE="Canada/Pacific"
  19. break
  20. ;;
  21. *) echo invalid option;;
  22. esac
  23. done
  24. }
  25.  
  26. get_shell() {
  27. PS3="Choose your shell: "
  28. options=("Zsh" "Bash")
  29. select opt in "${options[@]}"
  30. do
  31. case $opt in
  32. "Zsh")
  33. USER_SHELL="$HOME/.zshrc"
  34. break
  35. ;;
  36. "Bash")
  37. USER_SHELL="$HOME/.bash_profile"
  38. break
  39. ;;
  40. *) echo invalid option;;
  41. esac
  42. done
  43. }
  44.  
  45. setup_android_emulator(){
  46. AVD_NAME=$1
  47. AVD_TARGET=$2
  48.  
  49. echo "\nCreating AVD image $AVD_NAME"
  50. avdmanager create avd -c 64M -n $AVD_NAME -d "${AVD_DEVICE}" -k $AVD_TARGET
  51.  
  52. echo "hw.keyboard=yes" >> $HOME/.android/avd/$AVD_NAME\.avd/config.ini
  53. }
  54.  
  55. get_timezone
  56. echo
  57. get_shell
  58.  
  59. # =======================
  60. # install Java8 and Android SDK
  61. echo "\nInstalling Java8"
  62. brew cask install caskroom/versions/java8
  63.  
  64. echo "\nInstalling Android SDK"
  65. brew cask install android-sdk
  66.  
  67. # =======================
  68. # export shell path to work with Android
  69. echo "\n# Android PATHs" >> $USER_SHELL
  70. echo 'export ANDROID_HOME="/usr/local/share/android-sdk"' >> $USER_SHELL
  71. echo 'export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin/:$PATH"' >> $USER_SHELL
  72.  
  73. # create a function to easily start the emulator from the shell
  74. echo '\n# pass the parameter to be one of the created images api21, api24, api25, api26, or api27
  75. function startEmulator() { emulator -timezone '$TIMEZONE' -noaudio -no-boot-anim -memory 256 -avd $1& }' >> $USER_SHELL
  76.  
  77. ANDROID_HOME="/usr/local/share/android-sdk"
  78. PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin/:$PATH"
  79.  
  80. # =======================
  81. # install Android tools
  82. yes | sdkmanager --licenses
  83.  
  84. echo "\nInstalling Android SDK"
  85. sdkmanager --verbose "build-tools;27.0.3" \
  86. "docs" \
  87. "emulator" \
  88. "tools" \
  89. "extras;android;gapid;3" \
  90. "extras;android;m2repository" \
  91. "extras;google;google_play_services" \
  92. "extras;google;m2repository" \
  93. "extras;intel;Hardware_Accelerated_Execution_Manager" \
  94. "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2" \
  95. "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" \
  96. "patcher;v4" \
  97. "platform-tools" \
  98. "platforms;android-21" \
  99. "platforms;android-22" \
  100. "platforms;android-23" \
  101. "platforms;android-24" \
  102. "platforms;android-25" \
  103. "platforms;android-26" \
  104. "platforms;android-27" \
  105. "system-images;android-21;default;x86_64" \
  106. "system-images;android-24;default;x86_64" \
  107. "system-images;android-25;google_apis;x86" \
  108. "system-images;android-26;google_apis;x86_64" \
  109. "system-images;android-27;google_apis;x86"
  110.  
  111. echo "\nUpdating Android SDK"
  112. sdkmanager --update
  113.  
  114. # =======================
  115. # install Intel HAXM
  116. echo "\nEnter your admin password to silently install Intel Accelerated Execution Manager kernel extension" \
  117. && sudo sh /usr/local/share/android-sdk/extras/intel/Hardware_Accelerated_Execution_Manager/silent_install.sh
  118.  
  119. # =======================
  120. # Create a few AVDs
  121. # -d specified the device you'd like to use, choose and replace with your prefered device from 'avdmanager list device'
  122. echo "\nCreating AVD image for API 21"
  123. setup_android_emulator "api21" "system-images;android-21;default;x86_64"
  124.  
  125. echo "\nCreating AVD image for API 24"
  126. setup_android_emulator "api24" "system-images;android-24;default;x86_64"
  127.  
  128. echo "\nCreating AVD image for API 25"
  129. setup_android_emulator "api25" "system-images;android-25;google_apis;x86"
  130.  
  131. echo "\nCreating AVD image for API 26"
  132. setup_android_emulator "api26" "system-images;android-26;google_apis;x86_64"
  133.  
  134. echo "\nCreating AVD image for API 27"
  135. setup_android_emulator "api27" "system-images;android-27;google_apis;x86"
  136.  
  137. # =======================
  138. # For some reason Android complains if this file is missing, touch it.
  139. touch $HOME/.android/repositories.cfg
  140.  
  141. echo "\nInstallation successful, restart your shell"
Add Comment
Please, Sign In to add comment