Android 设备 adb 在 linux/Mac 上始终未经授权

Android device adb always unauthorized on linux/Mac

我不得不处理这个问题几次,每次我都忘记了原因是什么,直到我深入挖掘。所以这是症状:

adb shell blurb:

user@PC:~$ adb shell
error: device unauthorized.
This adbd's $ADB_VENDOR_KEYS is not set; try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.

adb devices blurb:

user@PC:~$ adb devices
List of devices attached
C4F124F1B9A98AE unauthorized

你的 udev 规则已经到位,从 lsusb 输出的代码出现在你的 /etc/udev/rules.d/51-android.rules(或 redhat 等价物,如果不同)

发生什么事了?

嗯,对我来说,问题是你在下面看到的:

user@PC:~$ ls -al ~/.android/
total 20
drwxrwxr-x  3 user    user 4096 Jun  7 15:46 .
drwxr-xr-x 30 user    user 4096 Sep 19 11:30 ..
-rw-------  1 root    root 1704 Jun  7 15:46 adbkey
-rw-r--r--  1 root    root  710 Jun  7 15:46 adbkey.pub
drwxrwxr-x  2 user    user 4096 Jun  7 15:42 cache

请注意我的 adbkey 和匹配的 public 密钥是如何归 root 所有的? 我第一次在这台机器上 运行 adb anything 是作为 root。 修复很简单,您可能已经知道了:sudo chown user:user ~/.android/adbkey*

这发生在我移动到新的 Mac 并使用全时 Mac 备份复制 Android Studio 时。在做了一些研究(实际上并没有导致原因)后,只需重新安装 Android Studio 就解决了问题。