2018-09-07 20:08:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the MIT license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
#
|
2015-12-30 19:38:13 +00:00
|
|
|
# inspired by https://github.com/Originate/guide/blob/master/android/guide/Continuous%20Integration.md
|
|
|
|
|
2018-07-24 23:25:44 +00:00
|
|
|
# shellcheck disable=SC1091
|
2018-05-16 00:25:16 +00:00
|
|
|
source "scripts/.tests.env"
|
2017-09-21 20:34:02 +00:00
|
|
|
|
2018-05-16 00:25:16 +00:00
|
|
|
function getAndroidPackages {
|
|
|
|
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools.bin:$PATH"
|
2015-12-30 19:38:13 +00:00
|
|
|
|
|
|
|
DEPS="$ANDROID_HOME/installed-dependencies"
|
|
|
|
|
2018-05-16 00:25:16 +00:00
|
|
|
# Package names can be obtained using `sdkmanager --list`
|
2018-07-24 23:25:44 +00:00
|
|
|
if [ ! -e "$DEPS" ] || [ ! "$CI" ]; then
|
2018-05-16 00:25:16 +00:00
|
|
|
echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, $AVD_ABI system image..."
|
|
|
|
sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
|
2017-09-21 20:34:02 +00:00
|
|
|
echo "Installing build SDK for Android API level $ANDROID_SDK_BUILD_API_LEVEL..."
|
|
|
|
sdkmanager "platforms;android-$ANDROID_SDK_BUILD_API_LEVEL"
|
|
|
|
echo "Installing target SDK for Android API level $ANDROID_SDK_TARGET_API_LEVEL..."
|
|
|
|
sdkmanager "platforms;android-$ANDROID_SDK_TARGET_API_LEVEL"
|
|
|
|
echo "Installing SDK build tools, revision $ANDROID_SDK_BUILD_TOOLS_REVISION..."
|
2018-05-16 15:49:57 +00:00
|
|
|
sdkmanager "build-tools;$ANDROID_SDK_BUILD_TOOLS_REVISION"
|
|
|
|
# These moved to "system-images;android-$ANDROID_SDK_BUILD_API_LEVEL;google_apis;x86" starting with API level 25, but there is no ARM version.
|
|
|
|
echo "Installing Google APIs $ANDROID_GOOGLE_API_LEVEL..."
|
|
|
|
sdkmanager "add-ons;addon-google_apis-google-$ANDROID_GOOGLE_API_LEVEL"
|
2017-09-21 20:34:02 +00:00
|
|
|
echo "Installing Android Support Repository"
|
|
|
|
sdkmanager "extras;android;m2repository"
|
2018-07-24 23:25:44 +00:00
|
|
|
$CI && touch "$DEPS"
|
2015-12-30 19:38:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-09-21 20:34:02 +00:00
|
|
|
function getAndroidNDK {
|
|
|
|
NDK_HOME="/opt/ndk"
|
|
|
|
DEPS="$NDK_HOME/installed-dependencies"
|
|
|
|
|
|
|
|
if [ ! -e $DEPS ]; then
|
2018-07-24 23:25:44 +00:00
|
|
|
cd $NDK_HOME || exit
|
2017-09-21 20:34:02 +00:00
|
|
|
echo "Downloading NDK..."
|
2018-07-30 20:54:03 +00:00
|
|
|
curl -o ndk.zip https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip
|
2017-09-21 20:34:02 +00:00
|
|
|
unzip -o -q ndk.zip
|
|
|
|
echo "Installed Android NDK at $NDK_HOME"
|
|
|
|
touch $DEPS
|
|
|
|
rm ndk.zip
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function createAVD {
|
2018-05-16 00:25:16 +00:00
|
|
|
AVD_PACKAGES="system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
|
|
|
|
echo "Creating AVD with packages $AVD_PACKAGES"
|
2018-07-24 23:25:44 +00:00
|
|
|
echo no | avdmanager create avd --name "$AVD_NAME" --force --package "$AVD_PACKAGES" --tag google_apis --abi "$AVD_ABI"
|
2017-09-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function launchAVD {
|
|
|
|
# The AVD name here should match the one created in createAVD
|
2018-07-24 23:25:44 +00:00
|
|
|
if [ "$CI" ]
|
2018-05-16 00:25:16 +00:00
|
|
|
then
|
2018-07-24 23:25:44 +00:00
|
|
|
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" -no-audio -no-window
|
2018-05-16 00:25:16 +00:00
|
|
|
else
|
2018-07-24 23:25:44 +00:00
|
|
|
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME"
|
2018-05-16 00:25:16 +00:00
|
|
|
fi
|
2017-09-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 19:38:13 +00:00
|
|
|
function waitForAVD {
|
2017-09-21 20:34:02 +00:00
|
|
|
echo "Waiting for Android Virtual Device to finish booting..."
|
2015-12-30 19:38:13 +00:00
|
|
|
local bootanim=""
|
2018-07-24 23:25:44 +00:00
|
|
|
export PATH=$(dirname $(dirname $(command -v android)))/platform-tools:$PATH
|
2015-12-30 19:38:13 +00:00
|
|
|
until [[ "$bootanim" =~ "stopped" ]]; do
|
|
|
|
sleep 5
|
|
|
|
bootanim=$(adb -e shell getprop init.svc.bootanim 2>&1)
|
2017-09-21 20:34:02 +00:00
|
|
|
echo "boot animation status=$bootanim"
|
2015-12-30 19:38:13 +00:00
|
|
|
done
|
2017-09-21 20:34:02 +00:00
|
|
|
echo "Android Virtual Device is ready."
|
2015-12-30 19:38:13 +00:00
|
|
|
}
|
2016-03-11 21:32:42 +00:00
|
|
|
|
|
|
|
function retry3 {
|
|
|
|
local n=1
|
|
|
|
local max=3
|
|
|
|
local delay=1
|
|
|
|
while true; do
|
|
|
|
"$@" && break || {
|
|
|
|
if [[ $n -lt $max ]]; then
|
|
|
|
((n++))
|
|
|
|
echo "Command failed. Attempt $n/$max:"
|
|
|
|
sleep $delay;
|
|
|
|
else
|
|
|
|
echo "The command has failed after $n attempts." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
done
|
|
|
|
}
|