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=4333796
13mkdir sdk
14curl --retry 20 https://dl.google.com/android/repository/sdk-tools-linux-${SDK}.zip -O
15unzip -q -d sdk sdk-tools-linux-${SDK}.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/tools/bin/sdkmanager --licenses --no_https | grep -v = || true
55yes | ./sdk/tools/bin/sdkmanager --no_https \
56        "emulator" \
57        "platform-tools" \
58        "platforms;android-${api}" \
59        "${image}" | grep -v = || true
60
61echo "no" |
62    ./sdk/tools/bin/avdmanager create avd \
63        --name "${1}" \
64        --package "${image}" | grep -v = || true
65