Travis CI AVD上的Android Instrumentation测试失败,但在本地模拟器上工作
Posted
技术标签:
【中文标题】Travis CI AVD上的Android Instrumentation测试失败,但在本地模拟器上工作【英文标题】:Android Instrumentation Test fail on Travis CI AVD but work on local emulator 【发布时间】:2017-01-31 03:47:31 【问题描述】:如果我在本地模拟器上运行仪器测试,它们会完美运行 10 次中的 10 次,但是当我尝试在 Travis CI 中的 AVD 上运行相同的测试时,我随机得到 p>
FAILED java.lang.RuntimeException: Could not launch intent Intent within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was xxxxxxx and now the last time the queue went idle was: xxxxxxxxx. If these numbers are the same your activity might be hogging the event queue.
我已尝试删除所有进度条和所有内容,但它仍然是一个仅随机发生在 Travis 上的问题。 我的 travis.yml 看起来像这样:
env:
global:
- android_TARGET=android-19
- ANDROID_ABI=armeabi-v7a
before_script:
- android list targets
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window -no-boot-anim &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- ./gradlew jacocoTestReport assembleAndroidTest connectedCheck zipalignRelease
【问题讨论】:
【参考方案1】:如果你想使用android-wait-for-emulator
脚本,请remove-no-boot-anim
选项depends on来检测模拟器何时准备就绪。
或者,将android-wait-for-emulator
脚本替换为固定的sleep time,如下所示:
- sleep 300
- adb shell input keyevent 82 &
您需要根据每个 API 启动时长选择休眠时间。
【讨论】:
以上是关于Travis CI AVD上的Android Instrumentation测试失败,但在本地模拟器上工作的主要内容,如果未能解决你的问题,请参考以下文章
Travis CI 跳过测试(Gradle Android 项目)
Android Travis CI 错误:所选目标的 --abi armeabi-v7a 无效