xref: /aosp_15_r20/external/executorch/.ci/docker/common/install_android.sh (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3# All rights reserved.
4#
5# This source code is licensed under the BSD-style license found in the
6# LICENSE file in the root directory of this source tree.
7
8set -ex
9
10# Double check if the NDK version is set
11[ -n "${ANDROID_NDK_VERSION}" ]
12
13install_prerequiresites() {
14  OS=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
15  case "$OS" in
16    amzn)
17      # https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/amazon-linux-install.html
18      yum install -y java-17-amazon-corretto \
19        ca-certificates \
20        ant
21      ;;
22    *)
23      apt-get update
24
25      # NB: Need OpenJDK 17 at the minimum
26      apt-get install -y --no-install-recommends \
27        openjdk-17-jdk \
28        ca-certificates-java \
29        ant
30
31      # Cleanup package manager
32      apt-get autoclean && apt-get clean
33      rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
34    ;;
35  esac
36}
37
38install_ndk() {
39  NDK_INSTALLATION_DIR=/opt/ndk
40  rm -rf "${NDK_INSTALLATION_DIR}" && mkdir -p "${NDK_INSTALLATION_DIR}"
41
42  pushd /tmp
43  # The NDK installation is cached on ossci-android S3 bucket
44  curl -Os --retry 3 "https://ossci-android.s3.amazonaws.com/android-ndk-${ANDROID_NDK_VERSION}-linux.zip"
45  unzip -qo "android-ndk-${ANDROID_NDK_VERSION}-linux.zip"
46
47  # Print the content for manual verification
48  ls -lah "android-ndk-${ANDROID_NDK_VERSION}"
49  mv "android-ndk-${ANDROID_NDK_VERSION}"/* "${NDK_INSTALLATION_DIR}"
50
51  popd
52}
53
54install_cmdtools() {
55  CMDTOOLS_FILENAME=commandlinetools-linux-11076708_latest.zip
56
57  pushd /tmp
58  # The file is cached on ossci-android S3 bucket
59  curl -Os --retry 3 "https://ossci-android.s3.us-west-1.amazonaws.com/${CMDTOOLS_FILENAME}"
60  unzip -qo "${CMDTOOLS_FILENAME}" -d /opt
61
62  ls -lah /opt/cmdline-tools/bin
63  popd
64}
65
66install_sdk() {
67  SDK_INSTALLATION_DIR=/opt/android/sdk
68  rm -rf "${SDK_INSTALLATION_DIR}" && mkdir -p "${SDK_INSTALLATION_DIR}"
69
70  # These are the tools needed to build Android apps
71  yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "platforms;android-34"
72  yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "build-tools;33.0.1"
73  # And some more tools for future emulator tests
74  yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "platform-tools"
75  yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "tools"
76}
77
78install_prerequiresites
79install_ndk
80install_cmdtools
81install_sdk
82