尝试将我的Android项目升级为 CircleCI 2.0 。一切都很好,但是无法使用模拟器运行Android UI测试。
com.android.builder.testing.api.DeviceException: No connected devices!
sdkmanager "system-images;android-22;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-22;default;armeabi-v7a" && (emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on) &
adb devices
不返回任何设备:(答案 0 :(得分:17)
示例circle.yml
:
version: 2
jobs:
build:
docker:
- image: circleci/android:api-26-alpha
steps:
- run:
name: Setup emulator
command: sdkmanager "system-images;android-22;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-22;default;armeabi-v7a"
- run:
name: Launch emulator
command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on
background: true
- run:
name: Run Tests
command: ./gradlew :demo:connectedAndroidTest
注意强>:
某些特定的架构图片并非由Google提供,例如: API级别26没有ARM EABI v7a系统映像,这就是我选择上面system-images;android-22;default;armeabi-v7a
的原因。要查看哪些图像可用,请运行命令sdkmanager --list --verbose | grep system-images
。
您需要使用LD_LIBRARY_PATH
和lib64
路径设置环境变量qt
,否则您可能会遇到ERROR: Could not load OpenGLES emulation library [lib64OpenglRender]
或error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory
Exited with code 127
。这是由于a bug from Android SDK。
要在CircleCI的后台运行命令,它不像通常的方式只是将&
附加到命令的末尾,最终会被挂断(HUP)信号杀死。正确的方法是说background: true
。
答案 1 :(得分:1)
以下是一个示例config.yml
,通过该示例,我设法使我的Android espresso测试使用回圈ci进行了一段时间。可能对某人有用。
config.yml
的位置:在项目根目录下创建.circleci
目录,并将config.yml
保留在其中。
version: 2
jobs:
build:
working_directory: ~/code
docker:
- image: circleci/android:api-28-alpha
environment:
JVM_OPTS: -Xmx3200m
steps:
- checkout
- restore_cache:
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Chmod permissions
command: sudo chmod +x ./gradlew
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
- save_cache:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Lists installed targets
command: android list target
environment:
TERM: dumb
- run:
name: Show list of system-images
command: sdkmanager --list --verbose | grep system-images
- run:
name: Setup Emulator
command: sdkmanager "system-images;android-21;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-21;default;armeabi-v7a"
- run:
name: Launch Emulator
command: |
cd ${ANDROID_HOME}/emulator;ls
export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib
emulator -avd test -no-window -noaudio -no-boot-anim -no-window -accel on
background: true
- run:
name: Wait emulator
command: |
circle-android wait-for-boot
adb shell input keyevent 82
- run:
name: Run Espresso UI Tests
command: ./gradlew :app:connectedDebugAndroidTest
- store_artifacts:
path: app/build/reports
destination: reports
- store_test_results:
path: app/build/test-results