Skip to content

Commit 7865481

Browse files
etlhsucketcham
authored andcommittedMay 8, 2019
Simplified AVD virtual device emulation within CI
Resolves material-components#338 GIT_ORIGIN_REV_ID=65991c1e6a9c7357e8ef6e9a9be8f87a7d5cf4df PiperOrigin-RevId: 247219512
1 parent 0cf8ef7 commit 7865481

7 files changed

+55
-129
lines changed
 

‎.travis.yml

+34-38
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
1-
language: android
2-
jdk: oraclejdk8
3-
4-
# Choosing faster environment since it's a full VM.
5-
# https://docs.travis-ci.com/user/reference/overview/
61
sudo: required
7-
dist: trusty
2+
language: generic
83

94
env:
5+
global:
6+
- ABI="google_apis;armeabi-v7a"
7+
- BUILD_TOOLS_VERSION=28.0.3
8+
- ADB_INSTALL_TIMEOUT=25
9+
- QEMU_AUDIO_DRV=none
1010
matrix:
11-
# Notice matrix environment variables are not available during the install phase for android >
12-
# components.
13-
# These CANNOT BE USED in the android > components section, only in before_script and script.
14-
- TEST_TYPE=unit
15-
- TEST_TYPE=instrumentation EMULATOR_TAG=android EMULATOR_API=16 ABI=armeabi-v7a
16-
- TEST_TYPE=instrumentation EMULATOR_TAG=android EMULATOR_API=19 ABI=armeabi-v7a
17-
- TEST_TYPE=instrumentation EMULATOR_TAG=android EMULATOR_API=21 ABI=armeabi-v7a
18-
19-
before_cache:
20-
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
21-
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
22-
23-
cache:
24-
directories:
25-
- $HOME/.gradle/caches/
26-
- $HOME/.gradle/wrapper/
27-
- $HOME/.android/build-cache
28-
29-
android:
30-
components:
31-
# https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943
32-
- tools
33-
- tools
34-
35-
before_install:
11+
- EMULATOR_API=16
12+
- EMULATOR_API=19
13+
- EMULATOR_API=21
14+
- EMULATOR_API=24
15+
16+
install:
17+
- export ANDROID_HOME=~/android-sdk-linux
18+
- wget -q "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" -O android-sdk-tools.zip
19+
- unzip -q android-sdk-tools.zip -d ${ANDROID_HOME}
20+
- rm android-sdk-tools.zip
21+
- PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
22+
- yes | sdkmanager --update
23+
- yes | sdkmanager --licenses
24+
- ./gradlew dependencies || true
25+
- sdkmanager "emulator" "tools" "platform-tools" > /dev/null
26+
- sdkmanager --list | head -20
27+
- sdkmanager "build-tools;$BUILD_TOOLS_VERSION" "platforms;android-$28" > /dev/null
28+
- sdkmanager "system-images;android-$EMULATOR_API;$ABI" > /dev/null
29+
- sdkmanager --list | head -15
3630
- mkdir "$ANDROID_HOME/licenses" || true
37-
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e" > "$ANDROID_HOME/licenses/android-sdk-license"
38-
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd\n504667f4c0de7af1a06de9f4b1727b84351f2910" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
31+
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
32+
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
3933

4034
before_script:
41-
- ./travis_before_script.sh
35+
- echo no | avdmanager create avd --force -n test -k "system-images;android-$EMULATOR_API;$ABI"
36+
- ./gradlew assembleDebugAndroidTest -PdisablePreDex --continue --stacktrace
37+
- $ANDROID_HOME/emulator/emulator -avd test -no-window &
38+
- bash android-wait-for-emulator
39+
- adb shell input keyevent 82
4240

4341
script:
44-
- ./gradlew assemble -PdisablePreDex;
45-
- ./travis_run_unit_tests.sh
46-
- travis_wait ./travis_set_up_emulator.sh
47-
- travis_wait 60 ./travis_run_instrumentation_tests.sh
42+
- ./gradlew test -PdisablePreDex --stacktrace
43+
- ./gradlew connectedAndroidTest -PdisablePreDex --stacktrace

‎android-wait-for-emulator

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set +e
2+
3+
bootanim=""
4+
failcounter=0
5+
timeout_in_sec=360
6+
7+
until [[ "$bootanim" =~ "stopped" ]]; do
8+
bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &`
9+
if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline"
10+
|| "$bootanim" =~ "running" ]]; then
11+
let "failcounter += 1"
12+
echo "Waiting for emulator to start"
13+
if [[ $failcounter -gt timeout_in_sec ]]; then
14+
echo "Timeout ($timeout_in_sec seconds) reached; failed to start emulator"
15+
exit 1
16+
fi
17+
fi
18+
sleep 1
19+
done
20+
21+
echo "Emulator is ready"

‎travis_before_script.sh

-19
This file was deleted.

‎travis_create_avd.sh

-16
This file was deleted.

‎travis_run_instrumentation_tests.sh

-18
This file was deleted.

‎travis_run_unit_tests.sh

-17
This file was deleted.

‎travis_set_up_emulator.sh

-21
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.