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