我想在 Travis CI 中使用模拟器构建和测试 Android 应用。
在我的本地机器上,我可以使用 android
和 avdmanager
工具创建模拟器,示例:
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
当我尝试使用 android
工具创建模拟器时(不需要,因为它已被弃用),结果发现它与我 mac 上安装的版本不同,需要不同的参数
我的 .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/