Ubuntu:Android 设备调试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3127539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:49:55  来源:igfitidea点击:

Ubuntu: Android device debug

androidlinuxubuntuadb

提问by Poku

I have a HTC Desire which i would like to debug and run my Android application on. But when i in Eclipse gets the Window where i can choose between devices my HTC Desire is listed with only questionmarks (????????). What am i doing wrong?

我有一个 HTC Desire,我想在它上面调试和运行我的 Android 应用程序。但是,当我在 Eclipse 中获得可以在设备之间进行选择的窗口时,我的 HTC Desire 只列出了问号 (????????)。我究竟做错了什么?

I have tried this:

我试过这个:

Enabled USB Debugging on my device and enabled debugging in my application Manifest.xml file.

在我的设备上启用 USB 调试并在我的应用程序 Manifest.xml 文件中启用调试。

In Terminal i have do this:

在终端我已经这样做了:

  1. Log in as root and create this file: /etc/udev/rules.d/51-android.rules.
  2. SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
  3. sudo service udev restart
  1. 以 root 身份登录并创建此文件:/etc/udev/rules.d/51-android.rules。
  2. 子系统=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
  3. 须藤服务 udev 重启

What else could i try or have forgotten?

我还能尝试什么或忘记了什么?

回答by EboMike

You need to run adb manually using sudo. If you just run adb without sudo (or if you let Eclipse/ADT do it for you), it won't have the permissions necessary to see your devices.

您需要使用 sudo 手动运行 adb。如果您只是在没有 sudo 的情况下运行 adb(或者如果您让 Eclipse/ADT 为您执行此操作),它将没有查看您的设备所需的权限。

If it's already running, then sudo adb kill-server and sudo adb start-server.

如果它已经在运行,那么 sudo adb kill-server 和 sudo adb start-server。

回答by gnac

Note: EboMike's accepted answer is INCORRECT.

注意:EboMike 接受的答案是不正确的。

I know this is an old question thread, but I stumbled across it trying to resolve the same problem. However the accepted answer was incorrect. There should be no need to run the adb server as root once you have your udev rules set correctly.

我知道这是一个旧的问题线程,但我偶然发现它试图解决同样的问题。然而,接受的答案是不正确的。一旦正确设置了 udev 规则,就不需要以 root 身份运行 adb 服务器。

Step 3 in http://developer.android.com/tools/device.htmlgives you the correct resolution. Specifically, add or modify /etc/udev/rules.d/51-android.rules with the following line:

http://developer.android.com/tools/device.html 中的第 3 步为您提供正确的分辨率。具体来说,使用以下行添加或修改 /etc/udev/rules.d/51-android.rules:

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0666", GROUP="plugdev" 

In this case 0bb4 is the vendor id for HTC. 0fff is the product id for Nexus One. Use the table at the above link, or lsusb to identify your device's vendor id & product id. eg

在这种情况下,0bb4 是 HTC 的供应商 ID。0fff 是 Nexus One 的产品 ID。使用上面链接中的表格或 lsusb 来确定您设备的供应商 ID 和产品 ID。例如

$ lsusb
Bus 001 Device 006: ID 18d1:4e22 Google Inc. Nexus S (debug)

18d1 is the vendor id of this particular device, and 4e22 the product id. You can leave off the "GROUP" definition if you want to enable access to this device to all users. If not, be sure to add yourself to the plugdev group if you are not in it already. After creating this file, restart or reload udev.

18d1 是此特定设备的供应商 ID,4e22 是产品 ID。如果您想允许所有用户访问此设备,您可以不使用“GROUP”定义。如果没有,请确保将自己添加到 plugdev 组(如果您尚未加入)。创建此文件后,重新启动或重新加载 udev。

udevadm control --reload-rules

If you had to add yourself to a group, you will need to logout and back in again.

如果您必须将自己添加到组中,则需要注销并重新登录。

Kill any old adb servers with "adb kill-server", plug your device in and run "adb devices". This will restart the server and you should now see your device. Running adb as root, even just to start the adb server, is not required. It is also generally a bad idea to run things as root unless it is absolutely required.

使用“adb kill-server”杀死所有旧的 adb 服务器,插入您的设备并运行“adb devices”。这将重新启动服务器,您现在应该会看到您的设备。以 root 身份运行 adb,即使只是为了启动 adb 服务器,也不是必需的。除非绝对需要,否则以 root 身份运行通常也是一个坏主意。

回答by Rocky Zhang

the device-id in the adb devicescommmand is actually using the serial number of the android usb devices.

命令中的设备idadb devices实际上是使用android usb设备的序列号。

So, if you get a null string from the serial number, it will display ???????????

所以,如果你从序列号中得到一个空字符串,它会显示 ???????????

In the adb server source code:

在 adb 服务器源代码中:

static size_t format_transport(atransport *t, char *buf, size_t bufsize,
                               int long_listing)
{
    const char* serial = t->serial;
    if (!serial || !serial[0])
        serial = "????????????";

So, it could be that your adb server is not running at root privilege, or your usb devices does't not allow adb server to read. A simple check would be using lsusb -v | grep iSerial to see if you can get the iSerial field of your android device.

因此,可能是您的 adb 服务器未以 root 权限运行,或者您的 USB 设备不允许 adb 服务器读取。一个简单的检查是使用 lsusb -v | grep iSerial 看看你是否可以得到你的安卓设备的 iSerial 字段。

Also, there're chances the iSerial string is not prepared well in the device. I've seen a lot of engineering product doesn't have the iSerial at all, or all of the devices are displaying the same device id.

此外,有可能 iSerial 字符串在设备中没有准备好。我见过很多工程产品根本没有 iSerial,或者所有设备都显示相同的设备 ID。

Some times, the driver will read a section of data in the flash which is programmed uniquely from device to device to make it iSerial/device id.

有时,驱动程序会读取闪存中的一段数据,该数据从设备到设备唯一地编程,以使其成为 iSerial/设备 ID。

回答by Dreamszz

I've managed to get my "bricked" Nexus S working again by doing what is said here. One small addition was necessary, though.

通过执行此处所说的操作,我已经设法让我的“变砖” Nexus S 再次工作。不过,有必要增加一点。

When you do an lsusband the USB subsystem tells you which Android device is attached, mine was giving me back:

当您执行 anlsusb并且 USB 子系统告诉您连接的是哪个 Android 设备时,我的正在返回给我:

$ lsusb
Bus 001 Device 006: ID 18d1:d001 Google Inc.

Note the d001and not any of the known states, i.e. 4e20, 4e21 or 4e22. So what I did is to add another row in 51-android.rulesspecifically with this unknownstate and mark it as "recovery/debug".

注意d001而不是任何已知状态,即 4e20、4e21 或 4e22。所以我所做的是在51-android.rules这个未知状态下专门添加另一行并将其标记为“恢复/调试”。

Disconnect and reconnect Android. Check lsusbagain to make sure it is at least seen. And... That gave me this

断开并重新连接 Android。lsusb再次检查以确保它至少被看到。而且...这给了我这个

$ adb devices
List of devices attached
34353601BB2000EC    recovery

instead of this

而不是这个

$ adb devices -l
List of devices attached 
????????????           no permissions usb:1-3

After that, I simply followed the howto for restoring the factory images. Hope it helps.

之后,我只是按照如何恢复出厂图像。希望能帮助到你。

回答by shashini dilrukshi

This is because you haven't given your adb the permission to access to your hardware. You have two solutions:

这是因为您没有授予 adb 访问硬件的权限。您有两种解决方案:

temporary-> kill all existing adb processes and restart with super user

临时-> 杀死所有现有的 adb 进程并以超级用户重新启动

ps -ef | grep adb | awk '{print }' | xargs kill

sudo adb server-restart

or

或者

sudo <your android SDK path>/platform-tools/adb server-restart

permanent-> add your devices to udev list Add following line to your /etc/udev/rules.d/51-android.rules as rootwith correct idVendorusing this list.

永久- >下面一行到你的/etc/udev/rules.d/51-android.rules设备添加到udev的列表添加为根与正确idVendor使用这个列表

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

followed by following command:

接着是以下命令:

chmod a+r /etc/udev/rules.d/51-android.rules

If adb doesn't work do the following:

如果 adb 不起作用,请执行以下操作:

sudo ln -s <your android SDK path>/platform-tools/adb /usr/local/sbin/adb

回答by Nikhil Raut

Make sure you installed sudo apt-get install android-tools-adb Now check sudo adb It will show help of adb

确保你安装了 sudo apt-get install android-tools-adb 现在检查 sudo adb 它将显示 adb 的帮助

Now please kill/start adb use following commands -

现在请使用以下命令杀死/启动 adb -

sudo adb kill-server sudo adb start-server

须藤亚行杀死服务器须藤亚行启动服务器

Lastly, sudo adb devices

最后,sudo adb devices

Hopefully this will work !!!

希望这会奏效!!!