小米2S 连接Ubuntu Android Studio

时间:2023-01-29 18:24:24

1. 首先打开手机上的开发者选项,USB调试。拨号:*#*#717717#*#*  ,手机会以Toast形式出现“……enable”字样。再次拨号可disable。

2. Ubuntu安装mtpfs;用lsusb命令查看当前usb端口占用;

3.手机连上电脑,再次lsusb,对比上次,新增的ID即小米手机usb ID。找到手机的连在电脑上的usb接口号:

wy@wy-Inspiron-:~/Downloads/android-studio/sdk/platform-tools$ lsusb
Bus Device : ID : Intel Corp. Integrated Rate Matching Hub
Bus Device : ID : Intel Corp. Integrated Rate Matching Hub
Bus Device : ID :
Bus Device : ID 1d6b: Linux Foundation 2.0 root hub
Bus Device : ID 1d6b: Linux Foundation 2.0 root hub
Bus Device : ID 1d6b: Linux Foundation 2.0 root hub
Bus Device : ID 1d6b: Linux Foundation 3.0 root hub
Bus Device : ID 0bda: Realtek Semiconductor Corp.
Bus Device : ID 1bcf: Sunplus Innovation Technology Inc.
Bus Device : ID :07da Intel Corp.

可知小米2s是 Bus 003 Device 008: ID 2717:9039

4. $ sudo vim /etc/udev/rules.d/70-persistent-net.rules,在里面添加:

SUBSYSTEM=="usb", SYSFS{idVendor}=="", MODE==""
SUBSYSTEM=="usb_device",SYSFS{idVendor}=="",MODE==""
SUBSYSTEM=="usb",ATTR{idVendor}=="",ATTR{idProduct}=="", SYMLINK+="android_adb"

保存退出。

5. 进入android sdk 文件夹下面/platform-tools,运行如下指令:

wy@wy-Inspiron-:~/Downloads/android-studio/sdk/platform-tools$ sudo ./adb kill-server
wy@wy-Inspiron-:~/Downloads/android-studio/sdk/platform-tools$ sudo ./adb devices
List of devices attached
d14a12fb unauthorized

6. 进入~/.android目录,在adb_usb.ini中添加如下设备号:

0x2717

最后结果是:

wy@wy-Inspiron-:~$ cd ~/.android/
wy@wy-Inspiron-:~/.android$ cat adb_usb.ini
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# USB VENDOR ID PER LINE.
0x2717
wy@wy-Inspiron-:~/.android$

7. 重启adb服务:

wy@wy-Inspiron-:~/Downloads/android-studio/sdk/platform-tools$ sudo ./adb kill-server
wy@wy-Inspiron-:~/Downloads/android-studio/sdk/platform-tools$ sudo ./adb devices
List of devices attached
d14a12fb device

完毕。然后可在Android Studio中选择小米2S进行调试了:

小米2S 连接Ubuntu Android Studio

此后每次开机或者连接手机,重启一次adb服务即可,即第7步。

在终端运行./adb devices的时候,在手机上点确认,同意此PC以调试模式连接手机。