我正在ARMv7开发板上构建安卓系统。出于某些原因,我想使用"adb shell“从我的PC操作系统。由于Android系统使用NFS服务器作为根文件系统,因此开发板和PC通过以太网连接。下面是我尝试过的方法(我在Android设备上拥有root访问权限):
在Android设备上(通过带putty的串口访问):
android@ubuntu:~$ setprop service.adb.tcp.port 5555
android@ubuntu:~$ stop adbd
android@ubuntu:~$ start adbd在Ubuntu主机上:
android@ubuntu:~$ adb connect 192.168.0.85:5555
connected to 192.168.0.85:5555
android@ubuntu:~$ adb shell
error: closed
android@ubuntu:~$ adb devices
List of devices attached
192.168.0.85:5555 device如消息所示,通过adb的连接似乎成功(连接到...),但是我无法"adb shell“到它。最奇怪的是,我仍然可以看到通过"adb设备“连接的设备。
我试图杀死adb服务器,然后重启它,但它也不起作用。
发布于 2015-04-10 11:16:29
我研究了adb的源代码,并用gdb进行了调试,最终找到了根本原因。
基本上,为了响应主机命令adb shell,adbd (运行在Android设备上的守护进程)应该打开一个伪终端,并派生另一个子进程来运行shell。这些都是在system/core/adb/services.c的create_subproc_pty函数中实现的
static int create_subproc_pty(const char *cmd, const char *arg0, const char *arg1, pid_t *pid)
{
....
int ptm;
ptm = unix_open("/dev/ptmx", O_RDWR | O_CLOEXEC); // | O_NOCTTY);
if(ptm < 0){
printf("[ cannot open /dev/ptmx - %s ]\n",strerror(errno));
return -1;
}
....
*pid = fork();
if(*pid < 0) {
printf("- fork failed: %s -\n", strerror(errno));
adb_close(ptm);
return -1;
}
....
}在我的开发板上,我发现unix_open函数失败了。这是因为PTY驱动程序没有内置到内核中,所以在系统上找不到设备/dev/ptmx。
要解决这个问题,只需选择Character Devices - Unix98 PTY驱动程序并重新构建内核,然后adb shell就可以工作了。
https://stackoverflow.com/questions/29294698
复制相似问题