android - 无法使用 avdmanager 创建 Travis CI android 模拟器

标签 android android-emulator travis-ci android-testing

我想在 Travis CI 中使用模拟器构建和测试 Android 应用。

在我的本地机器上,我可以使用 androidavdmanager 工具创建模拟器,示例:

echo no | android create avd --force --name test01 --package 'system-images;android-27;google_apis_playstore;x86'

echo no | avdmanager create avd --force --name test02 --package 'system-images;android-27;google_apis_playstore;x86' 

但是在 Travis 上 $ANDROID_HOME/tools/bin 中没有 avdmanager

enter image description here

当我尝试使用 android 工具创建模拟器时(不需要,因为它已被弃用),结果发现它与我 mac 上安装的版本不同,需要不同的参数

enter image description here

我的 .travis.yml 文件(为清楚起见删除了变量和构建步骤):

sudo: true
os: linux
dist: trusty
language: android

android:
  components:
  - build-tools-26.0.2
  - android-26

before_script:
- echo no | android create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'
#- echo no | avdmanager create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'

script:
- echo "DEBUG searching for avdmanager" && ls -lAp $ANDROID_HOME/tools/bin

请问我应该如何在 Travis CI 中创建 Android 模拟器?

最佳答案

在尝试了官方方法之后,我发现在 travis 上启动一个模拟器的最简单方法至少在 travis.xml

中有这个
before_install:
  # Install SDK license so Android Gradle plugin can install deps.
  - mkdir "$ANDROID_HOME/licenses" || true
  - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
  # Install the rest of tools (e.g. avdmanager)
  - sdkmanager tools
  # Install the system image.
  - sdkmanager "system-images;android-24;default;armeabi-v7a"
  # Create and start emulator for the script. Meant to race the install task.
  - echo no | avdmanager create avd --force -n emulatorApi24 -k "system-images;android-24;default;armeabi-v7a"
  - $ANDROID_HOME/emulator/emulator -avd emulatorApi24 -no-audio -no-window &

before_script:
  - android-wait-for-emulator
  # Disable animations
  - adb shell settings put global window_animation_scale 0 &
  - adb shell settings put global transition_animation_scale 0 &
  - adb shell settings put global animator_duration_scale 0 &
  - adb shell input keyevent 82 &

script: ./gradlew connectedAndroidTest # Run emulator tests

现在我的 travis 构建需要 20 分钟 :D

作为引用,检查工作示例的好地方是 U+2020 project .

关于android - 无法使用 avdmanager 创建 Travis CI android 模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47796066/

相关文章:

Android:在模拟器中模拟 WiFi?

php - 为什么 APC 无法在 Travis-CI 上的 PHP v5.5 中工作?

java - Android 的英语到印地语音译

java - onComplete() 在成功下载 pdf (Rxjava) 后永远不会被调用,但在使用 AsyncTask 时可以工作

android - 更改首选项的背景颜色

java - 如何在 Travis-CI 中跳过 Java Maven 项目的 gpg 签名

node.js - 使用 docker 时如何加快 CI 构建时间?

Android使用数据传输协议(protocol)http或https

java - ResultSet 关闭后不允许执行操作[SQL 异常]

新版本中的 Android 模拟器问题 - 模拟器进程已终止