Here’s how to debug an Unity3D Android application on a real device (not in Unity3D editor) over WIFI in Visual Studio. This recipe is written for Unity 2017.4 and Visual Studio 2017, maybe it works also in other versions.
Prerequisites:
1] Connect your Android phone to the same WIFI station as your development computer
2] Connect your Android phone with USB cable to your development computer
Step 1] Connect to device with ADB
- Get the IP number of your Android phone with command ‘adb shell ip addr show wlan0’:
$ adb shell ip addr show wlan0 24: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 3000 link/ether 2c:fd:a1:8c:dc:f1 brd ff:ff:ff:ff:ff:ff inet 192.168.25.221/22 brd 192.168.27.255 scope global wlan0 valid_lft forever preferred_lft forever inet6 fe80::2efd:a1ff:fe8c:dcf1/64 scope link valid_lft forever preferred_lft forever
IP adress in this case is: 192.168.25.221
- Make a connection using adb connect
If connect fails take a look at https://stackoverflow.com/a/41422712/676402
$ adb connect 192.168.25.221 connected to 192.168.25.221:5555
- Disconnect phone from USB cable
- Check WIFI connection with to device with:
$ adb devices List of devices attached 192.168.25.221:5555 device
Step 2] Prepare debug version of Unity3D app
In Unity3D, go to Android build settings and check ‘Development Build’ and ‘Script Debugging’:
Now deploy and run your application (control-b). It’s important to run the application because otherwise the AndroidPlayer debugger will not show up in the next dialog.
Step 3] Set Visual Studio breakpoint and debug
Now in Visual Studio open a script and put a breakpoint.
Go to Debug -> Attach Unity debugger and a dialog with two debuggers should appear (one for Unity3D editor, one for Android device):
Select the ‘AndroidPlayer (USB)’ item and Visual Studio goes in debug mode. Note: This step can take a while if then Unity project is big.
Now run the application on the device and the breakpoint should be hit 🙂
Like!
What to do if my Unity3D App repeatedly crashes ?
Visual Studio doesnt seem to help with finding the location or cause of crash.
try to get more info using logcat https://developer.android.com/studio/command-line/logcat
what for mac
I did everything and more ! And it just does’nt work !!! The device (Nexus 10) is not showing in the list and the adb is connected. Im using Visual studio 2019. I can communicate with the device from unity editor for debug log info or profiling etc … but i can’t trace in visual studio ….
how to do same for emulated device?