Xamarin 初試之Android設備開發設置


Android調試時可以通過USB連接進行調試也可以通過WiFi連接進行調試,使用WiFi連接要通過 Android Debug Bridge(ADB)進行連接,ADB在Android Studio下帶有也可以自己下載,Android Studio自帶的位於sdk\platform-tools下。本來在Xamarin官網看到過使用方法當時沒在意,后來想找又翻了很久,索性直接轉過來:

Connecting over WiFi

By default, the Android Debug Bridge (ADB) is configured to communicate with an Android device via USB. It is possible to to reconfigure it to use TCP/IP instead of USB. In order to do this, both the device and the computer must be on the same WiFi network. To setup your environment to debug over WiF issue these steps from the command line:

  1. Determine the IP address of your Android device. One way to find out the IP address is to look under Settings > Wi-Fi , and then tap on the WiFi network that the device is connected to. This will bring up a settings screen showing information about the network connection, similar to what is seen in the screenshot below:

    On some versions of Android the IP address won't be listed there but can be found instead under Settings > About phone > Status.

  2. Connect your Android device to your computer via USB.

  3. Next, restart ADB so that it using TCP on port 5555. From a command prompt, type the following command:

    adb tcpip 5555

    After this command is issued, your computer will not be able to listen to devices that are connected via USB.

  4. Disconnect the USB cable connecting your device to your computer.

  5. Configure ADB so that it will connect to your Android device on the port that was specified in step 1 above:

    adb connect 192.168.1.28:5555

    Once this command finished the Android device is connected to the computer via WiFi.

When you're done debugging via WiFi, it is possible reset ADB back to USB mode with the following command:

adb usb

It is possible to ask ADB to list the devices that are connected to the computer. Regardless of how the devices are connected, you can issue the following command at the command prompt to see what is connected:

adb devices

以上就是WIFI調試連接步驟了,然后本人比較懶,能動不動紙筆,能動鼠標不動鍵盤,又怕忘,所以就湊合寫了個批處理
@echo off
cls

echo ADB 手機WIFI調試連接助手

echo 初始化...
%ADB.exe目錄,有變動時重新寫該目錄值% cd E:\AndordStudio\Android\sdk\platform-tools E: if not exist adb.exe goto _error1 echo 按照以下步驟進行: :_step1 echo. echo setp1:獲取手機IP地址 set /p phoneIP= echo 手機IP:%phoneIP% ,1:重新輸入 set /p selectN= if selectN==1 goto _step1 echo. echo setp2:將手機用USB連接至電腦,完成后按任意鍵繼續 pause echo. echo setp3:adb設置 adb tcpip 5555 echo. echo setp4:斷開手機USB連接,完成后按任意鍵繼續 pause echo. echo setp5:開始WIFI adb connect %phoneIP%:5555 pause echo. echo step6:調試結束,恢復adb adb usb :_exit echo 退出 exit :_error1 echo 錯誤:沒有找到 adb.exe pause goto _exit

最后就是測試效果了,點開批處理,連上手機開始測試,測試是在Android項目去掉"使用共享運行時"和"使用快速部署"選項下進行的,

開着它們總是出錯:要么就是源代碼和實際運行不匹配(這個很坑,不報錯,但實際數據和代碼里面的明顯對不上,最恨的是對不上還能正常下斷點調試),要么就是程序運行不起來 輸出"無法連接到 logcat,GetProcessId 返回了: 0" 。不廢話了,說下測試效果,沒有讀秒,按下F5開始調試后帶着手機去看了下睡覺的女兒、收了下垃圾、喝了兩杯水、上了個廁所,我都快忘了它時,程序運行起來了。




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM