Skip to content

Commit

Permalink
NT-2144: Emulator on CI environment (#1341)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkariang committed Jul 30, 2021
1 parent 1898158 commit d9e6734
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 42 deletions.
36 changes: 33 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base_job: &base_job
resource_class: xlarge
docker:
- image: circleci/android:api-30
executor:
name: android/android-machine
resource-class: xlarge
working_directory: '~/project'
environment:
TERM: dumb
Expand All @@ -11,6 +11,8 @@ base_job: &base_job
version: 2.1
orbs:
codecov: codecov/codecov@1.1.5
android: circleci/android@1.0.3

jobs:
build:
<<: *base_job
Expand Down Expand Up @@ -57,6 +59,31 @@ jobs:
path: app/build/outputs
destination: tests

snapshot-test:
<<: *base_job
steps:
- checkout
- restore_cache:
keys:
- v5-android-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- v5-android-
- attach_workspace:
at: ~/project
- android/create-avd:
avd-name: Pixel_3a_API_30
system-image: system-images;android-30;google_apis;x86
install: true
- run: ./script/emulator/copy_emulator_configuration.sh
- android/start-emulator:
avd-name: Pixel_3a_API_30
post-emulator-launch-assemble-command: ""
- android/wait-for-emulator
- run: ./script/emulator/screenshot_config_emulator.sh
- android/wait-for-emulator
#- run: ./gradlew executeScreenshotTests
- android/save-gradle-cache:
cache-prefix: v1a

create_internal:
<<: *base_job
steps:
Expand Down Expand Up @@ -149,6 +176,9 @@ workflows:
- test:
requires:
- build
- snapshot-test:
requires:
- build
- create_internal:
requires:
- build
Expand Down
4 changes: 3 additions & 1 deletion script/emulator/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ sdcard.path=sdcard.img
tag.display=Google APIs
skin.name=1080x2220
hw.lcd.density=440
hw.keyboard=yes
hw.lcd.width=1080
hw.lcd.height=2220
hw.keyboard=yes
6 changes: 6 additions & 0 deletions script/emulator/copy_emulator_configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "Copy configuration to the emulator in order to have a concrete Screen size specified on config.ini"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cp $DIR/config.ini ~/.android/avd/Pixel_3a_API_30.avd/config.ini

18 changes: 5 additions & 13 deletions script/emulator/create_emulator.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if $ANDROID_HOME/tools/android list avd | grep -q Pixel_3a_API_30; then
if android list avd | grep -q Pixel_3a_API_30; then
echo "There is an existing an emulator to run screenshot tests"
exit 0;
fi

echo "Creating a brand new SDCard..."
rm -rf sdcard.img
$ANDROID_HOME/emulator/mksdcard -l e 1G sdcard.img
echo "SDCard created!"

echo "Downloading the image to create the emulator..."
echo no | $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-30;google_apis;x86"
echo no | sdkmanager "system-images;android-30;google_apis;x86"
echo "Image downloaded!"

echo "Creating the emulator to run screenshot tests..."
echo no | $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_3a_API_30 -k "system-images;android-30;google_apis;x86" --force --sdcard sdcard.img
echo no | avdmanager create avd -n Pixel_3a_API_30 -k "system-images;android-30;google_apis;x86"
echo "Emulator created!"


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cp $DIR/config.ini ~/.android/avd/Pixel_3a_API_30.avd/config.ini
cp sdcard.img ~/.android/avd/Pixel_3a_API_30.avd/sdcard.img
cp sdcard.img.qcow2 ~/.android/avd/Pixel_3a_API_30.avd/sdcard.img.qcow2
$DIR/copy_emulator_configuration.sh
6 changes: 0 additions & 6 deletions script/emulator/enable_animations.sh

This file was deleted.

2 changes: 1 addition & 1 deletion script/emulator/reboot_emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Rebooting emulator..."
$ANDROID_HOME/platform-tools/adb -e reboot
adb -e reboot
$DIR/wait_for_emulator.sh
echo "Emulator rebooted!"
12 changes: 3 additions & 9 deletions script/emulator/screenshot_config_emulator.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#!/bin/bash


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo "Specific configuration to avoid Facebook Screenshot library to fail on API devices higher than 27"
$ANDROID_HOME/platform-tools/adb wait-for-device
$ANDROID_HOME/platform-tools/adb shell settings put global hidden_api_policy_p_apps 1
$ANDROID_HOME/platform-tools/adb shell settings put global hidden_api_policy_pre_p_apps 1
$ANDROID_HOME/platform-tools/adb shell settings put global hidden_api_policy 1

echo "Rebooting emulator to apply the configuration"
$ANDROID_HOME/platform-tools/adb wait-for-device
echo adb shell settings put global hidden_api_policy_p_apps 1
echo adb shell settings put global hidden_api_policy_pre_p_apps 1
echo adb shell settings put global hidden_api_policy 1
11 changes: 4 additions & 7 deletions script/emulator/start_emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if ! $ANDROID_HOME/tools/android list avd | grep -q Pixel_3a_API_30; then
if ! android list avd | grep -q Pixel_3a_API_30; then
echo "No emulator for screenshot tests found, creating one..."
$DIR/create_emulator.sh
fi

if $ANDROID_HOME/platform-tools/adb devices -l | grep -q emulator; then
if adb devices -l | grep -q emulator; then
echo "Emulator already running"
exit 0
fi

echo "Starting emulator..."
echo "no" | $ANDROID_HOME/emulator/emulator "-avd" "Pixel_3a_API_30" "-no-audio" "-no-boot-anim" "-gpu" "swiftshader_indirect"&
$DIR/wait_for_emulator.sh

echo "Emulator ready, disabling animations!"
$DIR/disable_animations.sh
echo "no" | $ANDROID_HOME/emulator/emulator "-avd" "Pixel_3a_API_30" "-no-audio" "-no-boot-anim" "-gpu" "swiftshader_indirect"
$DIR/disable_animation.sh
$DIR/wait_for_emulator.sh

echo "Emulator ready, configuring for Screenshot Testing!"
Expand Down
2 changes: 1 addition & 1 deletion script/emulator/stop_emulator.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

echo "Stopping emulator..."
$ANDROID_HOME/platform-tools/adb emu kill
adb emu kill
echo "Emulator stopped!"
1 change: 0 additions & 1 deletion script/emulator/wait_for_emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

echo "Waiting until emulator is completely booted"
while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done
echo "Done"
echo "Emulator is ready"

0 comments on commit d9e6734

Please sign in to comment.