- Home /
Android Debug USB
Hello, I'm trying to debug my Unity application on an Android device, I would like to debug it trough +++USB+++ connection, because the WiFi debug is sure a fancy feature, but it is not suitable for actual working for obvious reasons (too much time to deploy in first place)
I don't mind doing it in MonoDeveloper or Visual Studio, at this point I wouldn't mind even doing it on windows notepad (JK, of course I want to do it in Visual Studio, but if there's no alternative MonoDeveloper would be fine too..).
I already wasted a lot of time searching on the internet how to do it, looking into the official documentation as well as on answers/forums, but it seems no one actually proposes a working question.
Here's some of the answers I found so far, non of them fits my senario:
https://docs.unity3d.com/Manual/AttachingMonoDevelopDebuggerToAnAndroidDevice.html?_ga=1.194662509.1315832825.1488531312 // Suggest to use WiFi debug
https://support.unity3d.com/hc/en-us/articles/205485376-How-do-you-debug-on-Android-?_ga=1.194662509.1315832825.1488531312 // No usefull answers
https://forum.unity3d.com/threads/any-tips-for-debugging-android.70197/ // Talks about unity 3.1
https://forum.unity3d.com/threads/attaching-monodevelop-debugger-to-an-android-device.245814/ // No usefull answers, most people refers to the WiFi usb solution
http://answers.unity3d.com/questions/175161/debugging-android.html // Someone suggests to do it in Eclipse, ridiculous, also I don't think it would work.
http://answers.unity3d.com/questions/976860/how-to-debug-an-android-application-in-visual-stud.html // Someone from ur team (I suppose) says that android debug currently works only via WiFi adding that " USB debugging is on our list with high priority", stated on 01/06/2015
Since I cannot believe that in 2017 there's no clear explantion on how to do it on the platform considered the standard for game development I hope somehow my careful search has somehow missed the internet page where how to do that is clearly exaplained step by step.
Thanks
you said an obvious reason for not profiling over WiFi would be the deployment time. But deployment is easily done using USB. It's just the "reading" that goes over WiFi and only for the profiler. logcat is also read over USB.
What exactly is it that you're missing?
$$anonymous$$y point is NOT to question about how good the WiFi debug works or how to get it work correctly after deploying trought USB, I'm asking how to do a USB debug, it seems a reasonable question to me and I don't think i'm asking for the moon or something. I said obvious reasons because thinking about the possible issues related to debugging trough WiFi they seem pretty obvious to me, I apologize for that, here's a few motivations that could make the WiFi debug unsuitable: I need to debug a method that is executed on Awake of my first scene without implementing workarounds. $$anonymous$$y company has 100+ people connected to the same WiFi working on unity and we all cannot afford to fill the network by continuously debugging trought wifi. $$anonymous$$y company does not use WiFi connection, we all are connected trought LAN. $$anonymous$$y company has a very strict policy on network security, tough all non standard ports are closed and we cannot afford to open them. Once again, I'm not asking how to make the WiFi debug work in my particular situation, I can already do that, I'm asking how to debug Android device trough USB supposing there's no WiFi network at all.
Answer by kostasandre · Mar 05, 2017 at 04:08 PM
Hello i am able to debug on vs and on monodevelop via usb. In VS go to Debug-> Attach unity debugger(Click on that first ,then launch ur app and you will see it in the menu click ok and ur done) In MonoDevelop Run-> Attach to Process and do the same as above Make sure you have adb on on your phone and all the sdk's needed
Hope this helps
This is indeed the correct answer! Thanks a lot! Still this is not specified anywhere in the documentation, also the debugger connection seem to be somehow unreliable: sometimes the "select unity instance" window correctly displays the connected device while sometimes it does not, that's what led me into asking how to do it here: even though I guessed that was the way to it I wasn't able to see my device in the "select unity instance" window in any way, and thus I tought I was doing something wrong. Trying to do it several times randomly made it work. I freshly installed both Unity 5.5.2 and Visual Studio 2015 on a brand new machine so I doubt there are issues related to an unclean Unity/VS installation
I'm hitting the same problem than $$anonymous$$angiarotti. I cannot see my Android device, currently running the game, in VS-Debug-Attach to Unity debugger. In your instructions, how did you "launch your app"? Did you use "Build&Run" from Unity?
This did indeed debug the app running on the device, but it did through wifi, at least for me. Am I missing something? Turning wifi off in the device will not list it in the Attach unity debugger menu.
Answer by ow3n · Aug 11, 2017 at 05:57 PM
I did all these things but eventually I realized (on my Samsung device) that I had to also enable debugging for the specific app as well. My steps for using ADB on the command line:
Android device go to Settings > Development
Turn development ON
Set USB debugging ON
Select app to be debugged (choose your app after first build)
On Mac
Install ADB: brew cask install android-platform-tools
In Unity Build settings: Development checked, Script debug checked
Build to Android
In Terminal
List devices attached: adb devices -l
Start debugging: adb logcat -s Unity DEBUG
Answer by FlyVC · Jul 13, 2020 at 11:31 AM
I tried everything that was suggested here and spent a whole day dealing with this S***
The final missing part was the empty "Preferred Android Sdk Root" path.
After copying the sdk path from Unity->preferences->external tools to VisualStudio->Tools->Options->ToolsForUnity->Debugging->Preferred Android Sdk Root the AndroidPlayer(USB) finally poped up in the Debug->SelectUnityInstance Menu and debugging finally works!
When the path is left blank, it should take the one that's set in Unity, but this seems bugged.
This worked for me. Thanks, your post saved me a day of work... or even more.
This! I had been frustrated for years and almost gave up on debugging via USB, and someone finally gave me a real solution! In fact, I failed at first and immediately thought this wasn't the answer either, but after trying some more times, it worked. Try again after killing the current adb process. Restarting Visual Studio and your Android app may help too.
Thank you bro!
Yesss! After hunting high & low, this was the missing part of the puzzle for me!
Answer by seaophiel · Jul 29, 2017 at 01:56 AM
After many hours finally today I was able to debug step by step from visual studio 2015, with my smartphone connected via USB
I did the following:
Have the device connected to the computer via USB
Have a keystore
In Unity Editor "File-> Build Settings" have selected android, Development checked, and script debug checked
Select "Build And Run"
From Visual Studio "Debug-> associate unity debugger (or select unity instance)" this will not show even the UBS device
I had to stop the game on my device and start it again
After restarting the game an wait a little this appeared in the list of devices connected in visual studio
8 After this I could debug normally like any visual studio application
I hope it works for someone Apologies for my basic english regards
For the first image on VS:
Debug>Attach Unity Debugger Select your device on the next window, while your app running. There is a check-mark on the Build Settings of Unity that you can allow for a delay before your app starts to setup your debugger. It is called: "Wait for managed debugger"
Thanks mate!
Answer by sora_jp · Mar 05, 2017 at 03:37 PM
Download the android sdk and install the platform tools. Then navigate to the platform_tools folder in the sdk and run adb logcat -s Unity
in a command prompt in the directory
Thanks but using -s flag just filters the logcat output by tag name, What I need is to debug, to be more clear I need my program to block its execution when a previously placed breakpoint is reached, allowing me to evaluate variables, procede in execution step by step etc.. Debug stuff, you know?
Your answer
Follow this Question
Related Questions
Problem with android on screen GUI 1 Answer
Is Screen.Orientation always portrait in Debug Mode? 0 Answers
Performance issues with touch/android build. 0 Answers
Keep getting AudioTrack messages when I use Android logcat with my unity app. 0 Answers
Deploying to Android or iPhone device - track public variables in inspector? 1 Answer