Skip to content

Commit

Permalink
Docker android: addressing AVD launch issue (facebook#30279)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#30279

Take in the fix from facebook#30273 + force starting adb server before launching AVD.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24638504

fbshipit-source-id: 7a379eb1db49ab418d9d91d20b49a02bbc0bc71c
  • Loading branch information
fkgozali authored and facebook-github-bot committed Oct 31, 2020
1 parent 864cdf3 commit 49d41c9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .circleci/Dockerfiles/Dockerfile.android
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# and build a Android application that can be used to run the
# tests specified in the scripts/ directory.
#
FROM reactnativecommunity/react-native-android:1.0.5
FROM reactnativecommunity/react-native-android:1.0.6

LABEL Description="React Native Android Test Image"
LABEL maintainer="Héctor Ramos <[email protected]>"
Expand Down
7 changes: 4 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ executors:
reactnativeandroid:
<<: *defaults
docker:
- image: reactnativecommunity/react-native-android:1.0.5
- image: reactnativecommunity/react-native-android:1.0.6
resource_class: "large"
environment:
- TERM: "dumb"
Expand Down Expand Up @@ -535,12 +535,13 @@ jobs:
name: "Run Tests: Android Unit Tests"
command: buck test ReactAndroid/src/test/... --config build.threads=$BUILD_THREADS --xml ./reports/buck/all-results-raw.xml
- run:
name: "Run Tests: Android Instrumentation Tests"
name: "Build Tests: Android Instrumentation Tests"
# Here, just build the instrumentation tests. There is a known issue with installing the APK to android-21+ emulator.
command: |
if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then
echo "JavaScript bundle missing, cannot run instrumentation tests. Verify Build JavaScript Bundle step completed successfully."; exit 1;
fi
source scripts/android-setup.sh && NO_BUCKD=1 retry3 timeout 300 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS
source scripts/android-setup.sh && NO_BUCKD=1 retry3 timeout 300 buck build ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS
# Optionally, run disabled tests
- when:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"prettier": "prettier --write \"./**/*.{js,md,yml}\"",
"format-check": "prettier --list-different \"./**/*.{js,md,yml}\"",
"update-lock": "npx yarn-deduplicate",
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:1.0.5",
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:1.0.6",
"docker-build-android": "docker build -t reactnativeci/android -f .circleci/Dockerfiles/Dockerfile.android .",
"test-android-run-instrumentation": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-instrumentation-tests.sh",
"test-android-run-unit": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-unit-tests.sh",
Expand Down
11 changes: 9 additions & 2 deletions scripts/.tests.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ export ANDROID_SDK_BUILD_TOOLS_REVISION=29.0.3
export ANDROID_SDK_BUILD_API_LEVEL="28"
# Google APIs for Android level
export ANDROID_GOOGLE_API_LEVEL="23"
# Minimum Android API Level we target
export ANDROID_SDK_TARGET_API_LEVEL="21"
# Minimum Android API SDK Level we target
export ANDROID_SDK_MINIMUM_API_LEVEL="21"
# Target API SDK level to build for
export ANDROID_SDK_TARGET_API_LEVEL="29"
# Android Image SDK level to install on the emulator
export ANDROID_SYSTEM_IMAGE_API_LEVEL="21"

# Android Virtual Device name
export AVD_NAME="testAVD"
# ABI to use in Android Virtual Device
export AVD_ABI=x86
# Temporarily disabling AVD related tests until newer system images can be installed.
export ANDROID_DISABLE_AVD_TESTS=1

## IOS ##
export IOS_TARGET_OS="14.1"
Expand Down
55 changes: 37 additions & 18 deletions scripts/android-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
# shellcheck disable=SC1091
source "scripts/.tests.env"

# NOTE: This doesn't run in Circle CI currently!
function getAndroidPackages {
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools.bin:$PATH"

DEPS="$ANDROID_HOME/installed-dependencies"

# Package names can be obtained using `sdkmanager --list`
if [ ! -e "$DEPS" ] || [ ! "$CI" ]; then
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"
echo "Installing Android API level $ANDROID_SYSTEM_IMAGE_API_LEVEL, Google APIs, $AVD_ABI system image..."
sdkmanager "system-images;android-$ANDROID_SYSTEM_IMAGE_API_LEVEL;google_apis;$AVD_ABI"
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..."
Expand Down Expand Up @@ -49,31 +50,49 @@ function getAndroidNDK {
}

function createAVD {
AVD_PACKAGES="system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
echo "Creating AVD with packages $AVD_PACKAGES"
echo no | avdmanager create avd --name "$AVD_NAME" --force --package "$AVD_PACKAGES" --tag google_apis --abi "$AVD_ABI"
if [ -z "$ANDROID_DISABLE_AVD_TESTS" ]
then
AVD_PACKAGES="system-images;android-$ANDROID_IMAGE_API_LEVEL;google_apis;$AVD_ABI"
echo "Creating AVD with packages $AVD_PACKAGES"
echo no | avdmanager create avd --name "$AVD_NAME" --force --package "$AVD_PACKAGES" --tag google_apis --abi "$AVD_ABI"
else
echo "Skipping AVD-related test setup..."
fi
}

function launchAVD {
# The AVD name here should match the one created in createAVD
if [ "$CI" ]
# Force start adb server
adb start-server

if [ -z "$ANDROID_DISABLE_AVD_TESTS" ]
then
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" -no-audio -no-window
# The AVD name here should match the one created in createAVD
if [ "$CI" ]
then
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" -no-audio -no-window
else
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME"
fi
else
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME"
echo "Skipping AVD-related test setup..."
fi
}

function waitForAVD {
echo "Waiting for Android Virtual Device to finish booting..."
local bootanim=""
export PATH=$(dirname $(dirname $(command -v android)))/platform-tools:$PATH
until [[ "$bootanim" =~ "stopped" ]]; do
sleep 5
bootanim=$(adb -e shell getprop init.svc.bootanim 2>&1)
echo "boot animation status=$bootanim"
done
echo "Android Virtual Device is ready."
if [ -z "$ANDROID_DISABLE_AVD_TESTS" ]
then
echo "Waiting for Android Virtual Device to finish booting..."
local bootanim=""
export PATH=$(dirname $(dirname $(command -v android)))/platform-tools:$PATH
until [[ "$bootanim" =~ "stopped" ]]; do
sleep 5
bootanim=$(adb -e shell getprop init.svc.bootanim 2>&1)
echo "boot animation status=$bootanim"
done
echo "Android Virtual Device is ready."
else
echo "Skipping AVD-related test setup..."
fi
}

function retry3 {
Expand Down

0 comments on commit 49d41c9

Please sign in to comment.