You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter内购测试:如何在GitHub Action中创建已登录Google Play的Android模拟器?

解决GitHub Action中Android模拟器登录Google Play的问题

针对你使用ReactiveCircus/android-emulator-runner时无法登录Google Play商店的问题,以下是可行的实现方案:

1. 选择带Google Play服务的系统镜像

android-emulator-runner支持指定预装Google Play的系统镜像,核心是配置正确的system-image参数:

  • 针对Android 12及以上版本,选择带_google_apis_playstore后缀的镜像,例如system-images;android-33;google_apis_playstore;x86_64
  • 这类镜像自带完整的Google Play服务和商店应用,是实现登录的基础

示例配置片段:

- name: 启动Android模拟器
  uses: ReactiveCircus/android-emulator-runner@v2
  with:
    api-level: 33
    system-image: "system-images;android-33;google_apis_playstore;x86_64"
    emulator-options: "-no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim"
    disable-animations: true

2. 自动完成Google Play账号登录

由于GitHub Action是无头环境,需通过ADB命令自动注入账号凭证完成登录:

  1. 在GitHub仓库的Secrets中存储测试用Google账号信息(建议使用专门的测试账号,关闭两步验证),比如GOOGLE_TEST_USER和GOOGLE_TEST_PWD
  2. 模拟器启动后,执行以下脚本完成登录:
# 等待Google Play商店启动
adb wait-for-device shell am start -n com.android.vending/com.android.vending.AssetBrowserActivity
sleep 10

# 输入账号并回车
adb shell input text ${{ secrets.GOOGLE_TEST_USER }}
adb shell input keyevent 66

# 输入密码并回车
sleep 5
adb shell input text ${{ secrets.GOOGLE_TEST_PWD }}
adb shell input keyevent 66

# 跳过后续引导步骤
sleep 5
adb shell input keyevent 66
sleep 5
adb shell input keyevent 66

3. 处理常见认证问题

  • 若出现Google Play服务认证失败,可通过ADB强制更新服务版本:
adb shell pm install -r --user 0 https://dl.google.com/android/repository/google_play_services.apk
  • 开启模拟器的模拟位置权限(部分场景需要):
adb shell settings put secure mock_location 1

4. 关键注意事项

  • 测试账号必须已添加到Google Play开发者控制台的测试账号列表中,否则无法访问应用内购商品
  • 绝对不要在日志中明文输出账号密码,必须通过GitHub Secrets存储敏感数据
  • 不同Android版本的ADB命令执行等待时间可能需要调整,可根据实际测试结果优化sleep时长

内容的提问来源于stack exchange,提问作者Manish Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 02:15:01