后退按钮在 android 模拟器上不起作用

Back button not working on android emulator

我尝试启动一个 android sdk 模拟器,但是当我按下后退按钮时出现此错误:

INFO    | Critical: Failed to load https://maps.googleapis.com/maps/api/mapsjs/gen_204?csp_test=true: The 'Access-Control-Allow-Origin' header has a value 'qrc://' that is not equal to the supplied origin. Origin 'qrc://' is therefore not allowed access. (qrc:/html/js/common.js:0, (null))

INFO    | Critical: Failed to load https://maps.googleapis.com/maps/api/mapsjs/gen_204?csp_test=true: The 'Access-Control-Allow-Origin' header has a value 'qrc://' that is not equal to the supplied origin. Origin 'qrc://' is therefore not allowed access. (qrc:/html/js/common.js:0, (null))

我使用 Ubuntu 并尝试通过终端启动模拟器,我使用 google cmdline-tools(最新版本)的 avdmanager,这是我尝试使用的 AVD:

    Name: my_avd_29ii
    Path: /home/user/.android/avd/my_avd_29ii.avd
  Target: Google APIs (Google Inc.)
          Based on: Android 10.0 (Q) Tag/ABI: google_apis/x86
  Sdcard: 512 MB

环顾四周,我发现有两种方法可以将硬件事件推送到模拟器:

First method

这个方法使用telnet,像这样:

telnet 127.0.0.1 5554
auth <auth-key>
event send EV_KEY:KEY_BACK:0
event send EV_KEY:KEY_BACK:1

这将模拟按钮的按下 (0) 和释放 (1)。

Second method

这个方法使用adb,像这样:

adb shell input keyevent KEYCODE_BACK

好吧,那又怎样?

两者都尝试后,我意识到 telnet 没有用,但 adb 确实 有用。我还检查了 emulator 的源代码,发现 telnet 依赖于 tool-window 使用的同一组函数。所以这可能是一个错误,我们可以等待更新修复它,或者...

同时

我下载了源代码,编写了一个 janky 解决方法,然后构建了它。基本上我没有使用按键方法,而是使用 adb 方法。如果你想要here it is。它非常庞大,所以请耐心等待。我包含了一个小脚本来自动替换模拟器,只是 运行:

$ chmod +x replace
# ./reaplace path-to-android-sdk

这向 emulator 添加了一个新标志 -use-adb-toolwindow。当您激活它时,它将使用 adb(成功)用于 大多数 键盘输入,以及主页、后退、应用程序和电源按钮。就像我说的那样,这是一个快速修复,但对我来说效果很好。

注:

我不知道错误在哪里,所以我没有做任何报告,希望随着更多人得到这个问题,它会变得更清楚。