如何通过命令行接受Android模拟器的调试对话框 [英] How to accept debugging dialog for Android Emulator via command line

查看:125
本文介绍了如何通过命令行接受Android模拟器的调试对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个自动模拟器脚本,该脚本将创建并启动一个Android模拟器,以便可以在任何计算机上运行UI测试,并保证它可以在设备上运行。



我当前的脚本创建了一个 android-27; google_apis; x86 设备,该设备运行良好,但缺少google服务,因此我的应用程序中的地图无法显示。 / p>

我尝试使用 google_apis_playstore 创建一个模拟器,但是当设备启动时,它会提示ADB调试提示。通常,轻按此按钮是可以的,但是我希望能够在无头服务器上运行它,并且永远不会。



无论如何,有没有创建模拟器来会有Google API +地图而无需必须接受ADB对话框吗?



这是我当前的shell脚本

 #!/ bin / sh 
#在根项目目录

#中运行此脚本#杀死现有的模拟器
$ ANDROID_HOME / platform-tools / adb设备| grep仿真器|切-f1 |边读边;做$ ANDROID_HOME / platform-tools / adb -s $ line emu kill;完成

#安装系统映像
$ ANDROID_HOME / tools / bin / sdkmanager system-images; android-27; google_apis; x86
是| $ ANDROID_HOME / tools / bin / sdkmanager --licenses

#创建模拟器
echo no | $ ANDROID_HOME / tools / bin / avdmanager create avd -f \
-n tester \
-k'system-images; android-27; google_apis; x86'\
-b x86 \
-d Nexus 5X

#启动模拟器
$ ANDROID_HOME / emulator / emulator -avd tester&

#等待仿真器启动
$ ANDROID_HOME / platform-tools / adb等待设备外壳输入keyevent 82
而[`$ ANDROID_HOME / platform-tools / adb shell getprop sys.boot_completed | tr -d'\r'`!= 1];睡1完成
睡眠5;

使用 google_apis_playstore 时出现错误

 错误:设备未授权。 
未设置此adb服务器的$ ADB_VENDOR_KEYS
如果这似乎不对,请尝试 adb kill-server。
否则,请检查设备上的确认对话框。

似乎很傻,您需要接受模拟器的调试权限吗?



编辑:我已将此错误提交为 https://issuetracker.google.com/issues/128271326

解决方案

默认值不同 google_apis google_apis_playstore 正在执行身份验证。这意味着主机上的 adb服务器和模拟器上的 adb守护程序都应共享相同的RSA adbkey 进行交流。文档在这里: https://developer.android.com/studio/command-line/ adb



通常它会自动运行。 adb启动服务器命令将创建 adbkey 文件,然后创建模拟器/模拟器会将它们复制到映像文件系统。但是由于在您的情况下它不起作用,因此您必须仔细验证错误配置的地方:




  • 运行 adb keygen adbkey 生成2个文件- adbkey adbkey.pub

  • 这2个文件需要复制到 $ HOME / .android 文件夹(或者 $ ANDROID_VENDOR_KEYS ),用于主机上的 adb 服务器

  • 需要将相同的2个文件复制到 $ HOME / .android 文件夹(或 $ ANDROID_SDK_HOME / .android )用于您的GUEST上的模拟器/模拟器。通常,HOST == GUEST,但是如果您在Docker容器内的桌面和模拟器上在桌面上运行 adb ,则它们是不同的。

  • 用于模拟器的文件系统是已缓存,因此请删除任何以前创建的图像。他们不会复制密钥。

  • (可选)在此处建议 https://developer.android.com/studio/command-line/adb#notlisted 调用 adb启动服务器明确地在发出任何 adb 命令之前




  $ adb杀毒服务器
$模拟器-avd Nexus_6_API_25-端口5557
$ adb起始服务器
$ adb设备

列表附加的设备
模拟器-5557设备



I'm writing an automated emulator script that will create and launch an Android emulator so I can run my UI tests from any machine and guarantee that it'll run on a device.

My current script creates an android-27;google_apis;x86 device which works fine, but lacks google services so the maps in my app do not show.

I tried creating an emulator using google_apis_playstore, but when the device boots, it prompts with an ADB debugging prompt. Normally tapping this would be fine, but Im expecting to be able to run this on a headless server and wont always be able to.

Is there anyway to create the emulator that will have google apis + maps without having to accept an ADB dialog?

Here's my current shell script

#!/bin/sh
# Run this script in root project dir

# Kill existing emulator
$ANDROID_HOME/platform-tools/adb devices | grep emulator | cut -f1 | while read line; do $ANDROID_HOME/platform-tools/adb -s $line emu kill; done

# Install system image
$ANDROID_HOME/tools/bin/sdkmanager "system-images;android-27;google_apis;x86"
yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses

# Create emulator
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -f \
    -n "tester" \
    -k 'system-images;android-27;google_apis;x86' \
    -b x86 \
    -d "Nexus 5X"

# Start emulator
$ANDROID_HOME/emulator/emulator -avd tester &

# Wait for emulator to start
$ANDROID_HOME/platform-tools/adb wait-for-device shell input keyevent 82
while [ "`$ANDROID_HOME/platform-tools/adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done
sleep 5;

I get an error when using google_apis_playstore because it can't adb in to check if the emulator has started because of the dialog.

error: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.

Seems silly that you would need to accept debugging permissions for an emulator?

Edit: I have submitted this as a bug https://issuetracker.google.com/issues/128271326

解决方案

Unlike default or google_apis, google_apis_playstore is enforcing authentication. It means that both adb server on host and adb daemon at emulator should share same RSA adbkey for communication. Documentation is here: https://developer.android.com/studio/command-line/adb

Typically it works automatically. adb start-server command will create adbkey files and then emulator/emulator will copy them into image filesystem. But since it doesn't work in your case you would have to carefully verify where things got misconfigured:

  • Running adb keygen adbkey generates 2 files - adbkey and adbkey.pub
  • These 2 files needs to be copied to $HOME/.android folder (alternatively $ANDROID_VENDOR_KEYS) for adb server on your HOST
  • Same 2 files needs to be copied to $HOME/.android folder (alternatively $ANDROID_SDK_HOME/.android) for emulator/emulator on your GUEST. Typically HOST==GUEST but if you are running adb on desktop and emulator inside docker container they are different.
  • Filesystem for emulator is cached so remove any previously created images. They wouldn't have key copied over.
  • Optionally, it is suggested here https://developer.android.com/studio/command-line/adb#notlisted to call adb start-server explicitly before issuing any adb commands

$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5557
$ adb start-server
$ adb devices

List of devices attached
emulator-5557 device

这篇关于如何通过命令行接受Android模拟器的调试对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆