1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3#
4# This source code is licensed under the MIT license found in the
5# LICENSE file in the root directory of this source tree.
6
7# This script validates that the Android environment is set up to run
8# tests on a device or emulator (as opposed to a plain Java environment).
9
10# This requires that the Android NDK is set up correctly and it also
11# requires that you are currently either running an emulator or have
12# an Android device plugged in.
13
14if [ -z "$ANDROID_NDK" ]; then
15  echo "Error: \$ANDROID_NDK is not configured."
16  echo "You must first install the Android NDK and then set \$ANDROID_NDK."
17  echo "If you already installed the Android SDK, well, the NDK is a different thing that you also need to install."
18  echo "See https://reactnative.dev/contributing/how-to-build-from-source for instructions."
19  exit 1
20fi
21
22if [ -z "$(adb get-state)" ]; then
23  echo "Error: you must either run an emulator or connect a device."
24  echo "You can check what devices are running with 'adb get-state'."
25  echo "You can run scripts/run-android-emulator.sh to get a known-good emulator config."
26  exit 1
27fi
28
29while :
30do
31    BOOTANIM=$(adb -e shell getprop init.svc.bootanim)
32    # shellcheck disable=SC2143
33    if [[ -n $(echo "$BOOTANIM" | grep stopped) ]]; then
34        break
35    fi
36    echo "Waiting for the emulator to finish booting..."
37    sleep 3
38done
39