Android debug on device

Hello! I am trying to debug a new project on an android device using Visual Studio (the project is empty, it just have a gameobject with 1 script) I connected my device by usb, run the adb commands to register the device with an static IP, then I can build and run, and it send the new apk via Wifi to my device and start the app, everything correct but the device is not listed in “Attach Unity Debugger” and if I put manually the IP/Port it display the Attach to IP/port but clicking on it just load for some seconds and come back without debugging. Someone have this running and can give a hand on what I am doing wrong? I tried too using Visual Studio Emulator for android (as suggested by this official video: https://unity3d.com/learn/tutorials/topics/scripting/testing-unity-games-android-visual-studio ) but have the same problem, the device is not displayed and cannot attach to the device. I discarded the need to open a port since the build & run send the .apk to the device correctly. Any Idea?

I did some debuggin on MonoDevelop. Process went like this:

  • Make sure developer options are enabled and usb debugging is enabled on the device.
  • Connect the device via usb cable.
  • from android sdk root run “adb devices” command. this will ist all devices connected. If the device is not listed, something is wrong and you may be missing necessary drivers.
  • run “adb tcpip” command. This will make adb attempt to restart in tcpip mode.
  • If the command freezes, unplug the device usb usb cable.
  • Run “adb connect device_ip_address”. Debugging will now work through wifi.
  • From within unity, use build & run command while in android mode (make sure it is marked as development build). It will attempt to find the device, build project and push it onto device (and attach profiler if enabled).
  • If this fails, make sure you have necessary drivers installed (my samsung tablet could not be debugged without kies installed first), and that adb did not decide to silently die (running any “adb” command from platform tools folder of android sdk will restart adb daemon)
  • Once the program is running on your tablet/phone, from MonoDevelop (because I don’t use visual studio in unity), select the game in the list of processes to attach to.

Based on your description you’re doing things differently and are trying to manually upload compiled project. I wouldn’t do that.

3 Likes

Hi neginfinity,

Thanks for the guide, I’m on the train back to home and I will try mono instead VS. When I said “It send the apk via wifi” I meant that my device is registered on adb and unity send the apk directly when I hit build and run. I sent the apk too building it first and then running adb install [apk path here]. Both install the apk on the device but VS seems is not capable to connect to the device process. I will try with Mono in a few minutes and if it works then I assume VS tool is bugged or misconfigured.

I made this work on VS, but when I use Attach Unity Debugger in VS, everytime the device have a different port, and when I connect to it, it freezes for 5 minutes, and then it start to work and I can debug on VS normally… but is very annoying. Anyone knows a way to fix this?

Any help with the above? I am working with it but is really annoying when I have to debug something and it needs 5 minutes to response a button click and then in the VS debugger is slow as hell.

Did you find a solution ? I’m facing the same issue

Check out the multicasting.
Generally, PC and the mobile have to use the same first 3 ip numbers
xxx.xxx.xxx.yyy
xxx.xxx.xxx.zzz

a few questions: are you guys using VIsualStudio or VisualStudio Code, and is there a different procedure/can VS Code even debug APKs, especially if they’re compiled using IL2CPP (required for google’s new x64 requirement for all apps)? And have you guys tried debugging just over USB without going over the network? Maybe that will be faster?

Debugging over USB that is the best decision for me. Stable and fast.

I use Microsoft Visual Studio Community 2019 and have no problem with IL2CPP.

Initially, you can start debugging on your device, decide if you want to connect the device using a USB cable or Wi-Fi.

Connect to your Device using USB
When you are set up and plugged in over USB, you can click Run in Android Studio to build and run your app on the device.

You can also use ADB to issue commands, as follows:

  • Verify that your device is connected by running the ADB devices command from your android_sdk/platform-tools/ directory. If connected, you’ll see the device listed.
  • Issue any ADB command with the -d flag to target your device.

I hope it was useful for our Android Developer