1#!/usr/bin/env sh 2 3set -ex 4 5# Prep the SDK and emulator 6# 7# Note that the update process requires that we accept a bunch of licenses, and 8# we can't just pipe `yes` into it for some reason, so we take the same strategy 9# located in https://github.com/appunite/docker by just wrapping it in a script 10# which apparently magically accepts the licenses. 11 12SDK=6609375 13mkdir -p sdk/cmdline-tools 14wget -q --tries=20 https://dl.google.com/android/repository/commandlinetools-linux-${SDK}_latest.zip 15unzip -q -d sdk/cmdline-tools commandlinetools-linux-${SDK}_latest.zip 16 17case "$1" in 18 arm | armv7) 19 api=24 20 image="system-images;android-${api};default;armeabi-v7a" 21 ;; 22 aarch64) 23 api=24 24 image="system-images;android-${api};google_apis;arm64-v8a" 25 ;; 26 i686) 27 api=28 28 image="system-images;android-${api};default;x86" 29 ;; 30 x86_64) 31 api=28 32 image="system-images;android-${api};default;x86_64" 33 ;; 34 *) 35 echo "invalid arch: $1" 36 exit 1 37 ;; 38esac; 39 40# Try to fix warning about missing file. 41# See https://askubuntu.com/a/1078784 42mkdir -p /root/.android/ 43echo '### User Sources for Android SDK Manager' >> /root/.android/repositories.cfg 44echo '#Fri Nov 03 10:11:27 CET 2017 count=0' >> /root/.android/repositories.cfg 45 46# Print all available packages 47# yes | ./sdk/tools/bin/sdkmanager --list --verbose 48 49# --no_https avoids 50# javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found 51# 52# | grep -v = || true removes the progress bar output from the sdkmanager 53# which produces an insane amount of output. 54yes | ./sdk/cmdline-tools/tools/bin/sdkmanager --licenses --no_https | grep -v = || true 55yes | ./sdk/cmdline-tools/tools/bin/sdkmanager --no_https \ 56 "platform-tools" \ 57 "platforms;android-${api}" \ 58 "${image}" | grep -v = || true 59 60# The newer emulator versions (31.3.12 or higher) fail to a valid AVD and the test gets stuck. 61# Until we figure out why, we use the older version (31.3.11). 62wget -q --tries=20 https://redirector.gvt1.com/edgedl/android/repository/emulator-linux_x64-9058569.zip 63unzip -q -d sdk emulator-linux_x64-9058569.zip 64 65cp /android/android-emulator-package.xml /android/sdk/emulator/package.xml 66 67echo "no" | 68 ./sdk/cmdline-tools/tools/bin/avdmanager create avd \ 69 --name "${1}" \ 70 --package "${image}" | grep -v = || true 71 72rm -rf commandlinetools-linux-${SDK}_latest.zip emulator-linux_x64-9058569.zip 73