about summary refs log tree commit diff
path: root/src/ci/docker/scripts/android-sdk.sh
blob: 99c5776c2e849a95b45d56dfdee5ed21d3a39e49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

set -ex

export ANDROID_HOME=/android/sdk
PATH=$PATH:"${ANDROID_HOME}/tools/bin"

download_sdk() {
    mkdir -p /android
    curl -fo sdk.zip "https://dl.google.com/android/repository/sdk-tools-linux-$1.zip"
    unzip -q sdk.zip -d "$ANDROID_HOME"
    rm -f sdk.zip
}

download_sysimage() {
    abi=$1
    api=$2

    # See https://developer.android.com/studio/command-line/sdkmanager.html for
    # usage of `sdkmanager`.
    #
    # The output from sdkmanager is so noisy that it will occupy all of the 4 MB
    # log extremely quickly. Thus we must silence all output.
    yes | sdkmanager --licenses > /dev/null
    sdkmanager platform-tools emulator \
        "platforms;android-$api" \
        "system-images;android-$api;default;$abi" > /dev/null
}

create_avd() {
    abi=$1
    api=$2

    # See https://developer.android.com/studio/command-line/avdmanager.html for
    # usage of `avdmanager`.
    echo no | avdmanager create avd \
        -n "$abi-$api" \
        -k "system-images;android-$api;default;$abi"
}

download_and_create_avd() {
    download_sdk $1
    download_sysimage $2 $3
    create_avd $2 $3
}

# Usage:
#
#       setup_android_sdk 4333796 armeabi-v7a 18
#
# 4333796 =>
#   SDK tool version.
#   Copy from https://developer.android.com/studio/index.html#command-tools
# armeabi-v7a =>
#   System image ABI
# 18 =>
#   Android API Level (18 = Android 4.3 = Jelly Bean MR2)