馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
ADB 功能簡介:ADB 全稱Android Debug Bridge, 是android sdk裡的一個工具, 用這個工具可以直接操作管理android模擬器或者真實的 andriod 設備。
操作功能說明:
[size=13.3333px]networking:
[size=13.3333px] connect HOST[:PORT] connect to a device via TCP/IP [default port=5555]
[size=13.3333px]執行指令使用:
[size=13.3333px]adb connect 192.168.2.133
[size=13.3333px]或
[size=13.3333px]adb connect 192.168.2.133:5555
[size=13.3333px]
[size=13.3333px]遇到問題:
[size=13.3333px]unable to connect to 192.168.2.160:5555: cannot connect to 192.168.2.160:5555: 無法連線,因為目標電腦拒絕連線。 (10061)
[size=13.3333px]
[size=13.3333px]接上 USB Debug 線,進入機器內部查看網路狀態:
[size=13.3333px]C:>adb devices --> 插入debug 線後 顯示 裝置
[size=13.3333px]List of devices attached
[size=13.3333px]20080411 device
[size=13.3333px]C:>adb shell netstat --> 以 Shell 指令查詢目前 裝置網路狀態
[size=13.3333px]Proto Recv-Q Send-Q Local Address Foreign Address State
[size=13.3333px] tcp 0 0 0.0.0.0:8554 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 127.0.0.1:5037 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 0.0.0.0:38421 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 0.0.0.0:1690 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 0.0.0.0:38431 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 0.0.0.0:1923 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 0.0.0.0:1960 0.0.0.0:* LISTEN
[size=13.3333px]....
[size=13.3333px]
[size=13.3333px]發現 5555 Port 並沒有啟動。
[size=13.3333px]先嘗試 其他 port 是否可用:
[size=13.3333px]C:>adb connect 192.168.2.160:8554 --> 用 8554 連看看
[size=13.3333px]connected to 192.168.2.160:8554
[size=13.3333px]C:>adb devices
[size=13.3333px]List of devices attached
[size=13.3333px]192.168.2.160:8554 offline --> offline No Work
[size=13.3333px]C:>adb shell --> 都已經跟你說 No Work 了 還硬要用嗎, 哈....
[size=13.3333px]error: device offline
[size=13.3333px]怎麼辦呢?? 只好直接啟動 5555 port 了。
[size=13.3333px]方法有三種:
[size=13.3333px]1.接上 Debug 線,直接啟動 5555 port,再以 網路方式 連接操作 --> 很無聊的舉動,多此一舉,而且每次開機都須重新執行一次。
[size=13.3333px]2.將啟動方式 建於 開機程序,每次開機 就會自動 啟動 5555 port --> 聰明多了,但若要 所有裝置 都如此 須更新 IMAGE 檔,有點小風險。
[size=13.3333px]3.運行的 APK 程式內 開機程序直接執行 啟動 5555 port --> 由 AP 來處理 風險少多了。
[size=13.3333px]一一來介紹吧:
[size=13.3333px]方法一:[size=13.3333px]直接啟動
[size=13.3333px]接上 Dubug 線,執行
[size=13.3333px]C:>adb tcpip 5555
[size=13.3333px]restarting in TCP mode port: 5555
[size=13.3333px]C:>adb shell
[size=13.3333px]root@android:/ # netstat | grep 5555 --> 找到 剛剛建的 5555 port 了
[size=13.3333px] tcp 0 0 0.0.0.0:5555 0.0.0.0:* LISTEN
[size=13.3333px]移除 Bebug 線,以 網路連接試試:
[size=13.3333px]C:>adb connect 192.168.2.160
[size=13.3333px]connected to 192.168.2.160:5555
[size=13.3333px]C:>adb devices
[size=13.3333px]List of devices attached
[size=13.3333px]192.168.2.160:5555 device
[size=13.3333px]C:>adb shell
[size=13.3333px]root@android:/ # netstat | grep 5555 --> 已經與 我的 PC 192.168.2.96 連上了
[size=13.3333px] tcp 0 0 0.0.0.0:5555 0.0.0.0:* LISTEN
[size=13.3333px] tcp 51 0 192.168.2.160:5555 192.168.2.96:1283 ESTABLISHED
此時你的 Android 開發平台 也可以 看到該裝置。
[size=13.3333px]方法二:[size=13.3333px]將啟動方式 建於 開機程序
[size=13.3333px]root@android:/ # cat /etc/install-recovery.sh --> 建一個 批次檔 於開機自動執行
[size=13.3333px]#!/system/bin/sh
[size=13.3333px]setprop service.adb.tcp.port 5555
[size=13.3333px]stop adbd
[size=13.3333px]start adbd
[size=13.3333px]重新啟動裝置後就可以直接 使用了,貼心提醒 注意 該文件權限喔。
[size=13.3333px][size=13.3333px]root@android:/ # ls -l /etc/install-recovery.sh
[size=13.3333px]-rw-rw-rw- root root 74 2017-07-05 10:23 install-recovery.sh
[size=13.3333px]root@android:/ # chmod 777 /etc/install-recovery.sh --> 確認權限可執行
[size=13.3333px]root@android:/ # ls -l /etc/install-recovery.sh
[size=13.3333px]-rwxrwxrwx root root 74 2017-07-05 10:23 install-recovery.sh
[size=13.3333px]
[size=13.3333px]重啟裝置後直接執行:
[size=13.3333px]C:>adb connect 192.168.2.160
[size=13.3333px]connected to 192.168.2.160:5555
[size=13.3333px]C:>adb shell
[size=13.3333px]root@android:/ # netstat | grep 5555
[size=13.3333px] tcp 0 0 0.0.0.0:5555 0.0.0.0:* LISTEN
[size=13.3333px] tcp 0 0 192.168.2.160:5555 192.168.2.96:1683 ESTABLISHED
[size=13.3333px]
[size=13.3333px]方法三:[size=13.3333px]運行的 APK 程式內 開機程序直接執行
[size=13.3333px]// 啟動 ADB 網路 控制 5555 port
[size=13.3333px]private void startADBTCPIPPort()
[size=13.3333px]{
[size=13.3333px] List<String> commands = new ArrayList<String>();
[size=13.3333px] commands.add("setprop service.adb.tcp.port 5555");
[size=13.3333px] commands.add("stop adbd");
[size=13.3333px] commands.add("start adbd");
[size=13.3333px] ShellUtils.execCommand(commands, true); --> 至於 直接 執行 Shell 方式 請自行完成囉
[size=13.3333px]}
|
|