Flutter 不会提示设备进行授权对话框

Flutter does not prompt the device for an authorization dialog

adb 可以通过 USB 和 WiFi 连接到我的设备(小米红米 4、MIUI 11.0.2、Android 7.1.2)。但是,我尝试连接 flutter 没有成功。当我通过 USB 连接时,Flutter 会检测到我的设备,但不会提示授权对话框:

$ flutter doctor

Doctor summary (to see all details, run flutter doctor -v):                                                                             
[✓] Flutter (Channel beta, v1.14.6, on Linux, locale en_US.UTF-8)                                                                       
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Android Studio (version 3.6)                                                                                                        
[!] Connected device                                                                                                                                                                                        
! Doctor found issues in 1 category.

$ flutter devices                                                                                                                         
No devices detected.                                                                                                                    

Run 'flutter emulators' to list and start any available device emulators.                                                               

Or, if you expected your device to be detected, please run "flutter doctor" to diagnose potential issues, or visit                      
https://flutter.dev/setup/ for troubleshooting tips.                                                                                    

• Device 9fd66a407d14 is not authorized.                                                                                                
You might need to check your device for an authorization dialog. 

我试过了

但是 flutter 仍然说我的设备未被授权。

有解决办法吗?

您可以尝试撤销 USB RSA 指纹并重新连接。

给你。

Settings -> Additional settings -> Developer options --> Revoke USB Debugging and Disconnect your device.

重新连接后,你会得到一个RSA指纹验证window,点击接受。完成。

注: 如果您的 phone 配置了多个用户帐户,请确保您使用的是主用户帐户(管理员)。

我在使用 adb 时遇到了另一个问题,当我通过 USB 或 WiFi 连接到我的设备时,即使在我检查 "Always allow from this computer" 之后它也会提示我进行授权(更多一年多,我从来不知道为什么)

原来是因为我有 ~/.android/adbkey 归 root 用户所有。因此,作为普通用户,adb 将无法写入该文件,这意味着它无法记住设备。我用 in this answer:

的步骤解决了这个问题

As described in this issue, this can happen if you run adb for the first time as root. It creates a key file on your computer owned by the root user, so your normal user account can't read or overwrite it.

To check if this is the case:

$ ls -l ~/.android/adbkey
-rw------- 1 root root 1708 Nov 13  2012 .android/adbkey
             ^ notice root here

To fix it:

$ sudo chown $USER: ~/.android/adbkey
$ ls -l ~/.android/adbkey
$ -rw------- 1 thomas thomas 1708 Nov 13  2012 /home/thomas/.android/adbkey
               ^ now shows your username and primary group

Finally, restart the adb server:

$ adb kill-server
$ adb start-server

一旦我解决了这个问题,Flutter 就完美地工作了!

正如 Darish 先生所建议的... 设置 -> 附加设置 -> 开发者选项 -> 撤销 USB 调试并断开你的设备(这将删除以前的授权并要求新的)。

但有时它不起作用。所以就去 设置 -> 其他设置 -> 开发人员选项 -> Select USB 配置 -> Select 那里有充电选项。它将显示授权对话框。

我正在使用 windows 10,我认为它不会直接帮助你,我只是想分享我的问题是如何解决的,并可能帮助那里的人

使用 android studio - 查找菜单工具 > sdk 管理器

在 sdk 管理器中找到 -> 外观和行为 |系统设置 | Android SDK 在 android sdk 找到 SDK 工具菜单并安装 Google USB 驱动程序

在设备管理器(Win + R -> devmgmt.msc)安装 adb 的 Google USB 驱动程序(在我的例子中,我的 phone 已经安装并且我更新了驱动程序) .

之后我们必须连接phone并信任计算机(我建议先打开usb调试并在开发者选项中撤销所有usb调试权限)