What are some ways to debug Unity 3.1 on Android? I find no docs or posts, and the manual always says 'not available'. Is there a crash log as with iPhone? Any sort of dumps or diagnostics? (My app runs fine on all other platforms, so it's not like that) Would the Mono Development be the place? If so, tips/links please! I'm new to MonoDevelopment and the Android SDK in general
There is something called the logcat, which is a combined message pipe from all applications. To read it you first need to locate the adb tool that comes with the Android SDK. Depending on which version you have of the SDK the adb is located either under <sdk>/tools or<sdk>/platform-tools. Simply start it like this: $ adb logcat and it will start printing out everything that is going on on the device. To limit it to only show the output from inside Unity, you can try this: $ adb logcat -s Unity or, to get a little bit more info about what's going on: $ adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG If you wish to report a bug or otherwise 'quote' the logcat, you can dump the complete logcat to a file like this: $ adb logcat -d > logcat.txt No, or not just yet. MonoDevelop does not support 'remote' debugging against Android today.
Thanks. I see that starting the Terminal app and using good-ole-fashioned CLI I can dump what's going on. Low on memory, big surprise. I see this DDMS remote debugger tool in the Android SDK, could that help? Is that going to be integrated into MonoDev or even (gulp) Unity some day?
You would use Terminal, which is the mac shell and then navigate to your sdk installs bin path to call adb. And no DDMS can't help as this is NDK, not Java.
You find the Terminal.app under Applications / Utilities. cd to <sdk>/tools (or <sdk>/platform-tools, if you have a the Gingerbread SDK installed), and execute it with ./adb . Yes, DDMS does the same thing, and lot of other things as well. The logcat is displayed at the bottom part of the window. It can also be used to capture the screen. Not impossible, but so far we've had more important tasks to deal with.
Thats true, my error. Forgot about that part, was too focused on the "debugging" where Google is still leaving people in their promised NDK debugging gap.
I created a debug window to display debug statements in the code. The window opens and closes with a button and the text can be cleared. Debug also appears in the console so I just use this debug call for all debugging. Just add this code to a game object. Code (csharp): using UnityEngine; using System.Collections; public class GuiTextDebug : MonoBehaviour { private float windowPosition = -440.0f; private int positionCheck = 2; private static string windowText = ""; private Vector2 scrollViewVector = Vector2.zero; private GUIStyle debugBoxStyle; private float leftSide = 0.0f; private float debugWidth = 420.0f; public bool debugIsOn = false; public static void debug(string newString) { windowText = newString + "\n" + windowText; UnityEngine.Debug.Log(newString); } void Start () { debugBoxStyle = new GUIStyle(); debugBoxStyle.alignment = TextAnchor.UpperLeft; leftSide = 120; //Screen.width - debugWidth - 3; } void OnGUI () { if (debugIsOn) { GUI.depth = 0; GUI.BeginGroup (new Rect(windowPosition, 40.0f, leftSide, 200.0f)); scrollViewVector = GUI.BeginScrollView (new Rect (0, 0.0f, debugWidth, 200.0f), scrollViewVector, new Rect (0.0f, 0.0f, 400.0f, 2000.0f)); GUI.Box (new Rect (0, 0.0f, debugWidth - 20.0f, 2000.0f), windowText, debugBoxStyle); GUI.EndScrollView(); GUI.EndGroup (); if (GUI.Button(new Rect (leftSide, 0.0f,75.0f,40.0f), "Debug")){ if (positionCheck == 1){ windowPosition = -440.0f; positionCheck = 2; } else { windowPosition = leftSide; positionCheck = 1; } } if (GUI.Button(new Rect (leftSide + 80f,0.0f,75.0f,40.0f),"Clear")){ windowText = ""; } } } }
Ok, so I can see one of my Debug.Log statements in the logcat (sometimes) Just before what looks like a 'core dump' it says signal 7 (SIGBUS) fault addr 00000000 My guess is it's a reference through a null pointer (or something)? I don't have this problem on iPod, nor in the editor, nor windows, nothing to indicate what might be going on. The registers and stack mean nothing to me. Is there any way to narrow-down what might be going on?
Your guess seems correct. The part just after the registers that looks something like this: #xx pc/lr xxxxxxxx /system/lib/lib<somelib>.so is interesting. There is currently no easy way available to turn those addresses into symbols, but looking at which library it crashed in is a good start.
Thanks. Looks like: #00 pc 00034284 /data/data/com.mycomp.myapp/lib/libunity.so #01 pc 0017a568 /data/data/com.mycomp.myapp/lib/libunity.so Any tips on how to proceed? It crashes on startup (splash screen is there for several seconds while it GC frees memory). I've disabled and commented-out most of the scripts, certainly recent ones (this app used to work just fine, but I've been adding things). I could put Debug.Log() into Start and Update but I loathe doing that. If we could #define things it wouldn't be so bad I guess. Any other techniques?
Ouch, that is a crash inside Unity. I assume you are using version 3.1? Unfortunately Debug.Log() / commenting out code will probably be the 'fastest' way forward. If turns out to be hopeless please report the bug and attach a project which exhibits the problem (as small project as possible is appreciated).
Thanks. Yes 3.1f Working on that. Looks like several problems. I commented out (or disabled) pretty much all scripts, it still dies (but now with SIGSEGV (11). Looks like certain shaders are to blame (ones that used to work before!?!?), namely Reflective/Bumped Specular. Also having some trouble with one particular object with a Transparent/Bumped Specular (although other nearly identical (except for mesh and transform) objects behave ok), and it may be that objects with Diffuse, but no texture assigned, cause trouble too. I need to get my project back up and running for a demo, but will try to send a small problematic example ASAP.
This tutorial might help you its easy to implement, just convert a simple java class that logs to DDMS to a jar file add it to Unity and write a simple plugin to use it, then you can view your logs from Eclipse DDMS tool .. http://nevzatarman.wordpress.com/
I have added this code to an Empty GameObject and enabled DebugIsOn in the Editor. But I cannot see any debug messages when I pressed the Debug Button .
Any updates here? I would really love to be able to have monodevelop attach/debug my game running on my Android device. The game runs very differently on the device vs the editor but without any way to debug I'm not sure why.
After debugging all day I learned two things, hopefully someone else find useful. 1) The tool mentioned above is great! http://u3d.as/content/dreammakersgroup/log-viewer/5E8 Simply drag the prefab into your scene. That allowed me to find my bug which is explained here: 2) XML loads have to be done with Resources.Load http://answers.unity3d.com/questions/377514/xml-loading-works-in-pc-but-not-in-android.html
Similar problems here more than four years later with last Unity version. With an actual Android device, the device is not shown at all in Mono. No matter if it is connected thru USB or thru WiFi, while it is reachable without problems at all with 'adb' tool from command line without problems at all. With an Emulator it is slightly different: mon can actually see the device there, but when you select it and click on "Attach", it will try to attach the debugger for a loooooong while to finally say that it couldn't do it (for no specific reason, BTW). Annoying.
Apparently you can attach MonoDevelop to a device now http://docs.unity3d.com/Manual/AttachingMonoDevelopDebuggerToAnAndroidDevice.html . A couple of notes: 1. Having the same subnet mask and gateway just seems to mean to make sure you connect your device to the internet the same way your pc is connected (so if your pc is on a wireless connection, connect to the same wireless connection with your device). 2. If you can't connect to the device try typing "adb kill-server" and then "adb start-server" and then resume from the "adb tcpip 5555" step.
when i entered adb logcat i got this lines comming. Code (CSharp): adb server is out of date. Killing.
[Disclaimer: I'm the developer of Loginator] Another tool you might want to use (if you're running on Windows) is a tool called Loginator. The advantage of this is that you don't have to be connected to Unity. The only thing you need is an android sdk installation, your android device and a USB cable. As you see in the picture below you can filter the output by search criteria, application (the number) or the TAG inside you application used for logging. The "Invert" is especially useful as Unity prints a "dummy line" which can be hidden by checking Invert, enter "UnityEngineDebugBindings" and click the Search button, only the messages of your application will be displayed. You can download it here: https://github.com/dabeku/Loginator/releases How to use it: 1. Open Loginator -> Configure... -> Choose Logcat (Android) -> Accept 2. Connect your Android device to your PC or Mac via USB 3. Find your device ID: /[path-to]/Android/sdk/platform-tools/adb devices 4. Forward the logcat output to your machine with Loginator running (sometimes it's required to restart the command below as ncat.exe/nc stops sending messages) Windows: [path-to]\Android\sdk\platform-tools\adb.exe -s [your-device-id] logcat | ncat.exe -u [ip-where-loginator-runs] 7081 Please note: As ncat.exe is not part of Windows, you have to download nmap first and use ncat.exe from there. To do that simply visit https://nmap.org/download.html locate and download the "Latest command-line zipfile". Unpack the .zip and take the files: libeay32.dll, ncat.exe and ssleay32.dll and copy them in a separate folder. You now have a valid ncat.exe application. Mac: cat <(/[path-to]/Android/sdk/platform-tools/adb -s [your-device-id] logcat) | nc -u [ip-where-loginator-runs] 7081 Please let me know if you like it or have suggestions on how to improve this tool.
A recently problem on unity 5.3.3.f1 and windows phone: Assets\Reporter\Test\TestReporter.cs(64,35): error CS0246: No se puede encontrar el tipo o el nombre de espacio de nombres 'ThreadStart' (�falta una directiva using o una referencia de ensamblado?)
I have used adb logcat before, but it was very annoying. So i give up using adb logcat and made a plugin named Device Console. It provides an in-game console to view full Unity console logs on devices. And it's easy to use. You can check it out here: https://www.assetstore.unity3d.com/#!/content/44935 Enjoy it
If you are looking for a computer-based GUI solution like dabeku's Loginator, you can try Android Device Monitor. ABM is a tool located in Android SDK/tools as "monitor" (monitor.bat on Windows). Run the file, it will take some time to load and ask you if you want to send usage stats to Google the first time. ADM immediately knows which port to listen to and will start log your device's activity as logcat does, and that's a lot of stuff so you need to filter it in the "Search for messages" input field in the LogCat tab (you'll probably need to extend it to see better). Now use a combination of app: and text: filter to get what you want. The filter "app:myApp" is not enough, as irrelevant messages such as "UnityEngine calling the log" (which does not state the actual log content) or "your method has been called in your script" will appear (but those messages may be useful depending on what you want to debug). Irrelevant log examples: Code (csharp): 04-02 15:58:02.084: W/Unity(18048): UnityEngine.Logger:LogFormat(LogType, String, Object[]) 04-02 15:58:02.084: W/Unity(18048): UnityEngine.Debug:LogWarningFormat(String, Object[]) 04-02 15:58:02.084: W/Unity(18048): TouchArea:AddPathVertex(Vector2) (at F:\Projects\Video Games\[My Unity Project Path]\Assets\Game\Recognition\Scripts\TouchArea.cs:201) I use a Regex with negative lookahead to exclude such messages. You just have to identify typical expressions and replace them in the negative lookahead regex patterns. You'll find some examples at http://stackoverflow.com/questions/...messages-by-tag-name-using-android-adb-logcat and http://stackoverflow.com/questions/...sion-to-match-line-that-doesnt-contain-a-word Some examples of filters: My game is on my F disk on Windows: app:com\.MyOrganization.MyApp text:^((?!(UnityEngine|F:\\)).)*$ I want to exclude logs containing "at [something] .cs" (because they just state one of my methods have been called) in all my running apps: app:com\.MyOrganization text:^((?!(at.*\.cs)).)*$ Note that the latter does not work if project path is too long and the log is cut by logcat before .cs extension appears. It looks like a bitrate issue since the max log size should be around 4000 ASCII characters, but I could not find a setting to fix that. However, the line gets cut only when I use that filter... Not sure why. Or, a more concise example probably enough for your app: app:MyApp text:^((?!(UnityEngine|\(at.*MyApp)).)*$ You can also get rid of Sensor Accelerometer log and the like by selecting "info" in the drop-down menu on the right of the filter input field. But it all depends on your app. Of course, don't forget positive filtering by starting all your logs with some [CATEGORY] tag. If you use positive filtering, you probably don't have to care about negative filtering anymore. I hope that will help you will your future Android development. I have to find an equivalent for iOS now...
Debugging server or desktop apps is pretty trivial. In your preferred IDE, you literally press ‘debug’ and just break through code as it runs. The same can be said for mobile apps inside of a simulator. As you move into the physical world, things get marginally trickier because you now need a physical mobile device, and a cable. Now, what happens when you want to go off-script and do something crazy, like debug your mobile app WITHOUT a physical cable? Here are 4 tips to debug your android app. Let me know if any of them works for you. 1. Wired debugging 2. Wireless debugging 3. Home wifi network 4. Isolated router
I often debug our game running on an Android device. Works fairly well, with the occasional debugger disconnections. I just make sure that the device and the debugging machine are connected to the same WIFI network.
Apologies for necroing this old post but I sell a debug tool on the Asset Store that might be useful for some of you. It's called Hdg Remote Debug. It's a live update and debug tool that lets you inspect the GameObjects, components, and serialized fields in your game after it has been deployed onto your Android device (it supports most platforms that Unity supports). You can tweak fields on the live build while sitting in the Unity editor, and it's great for quickly iterating on settings like UI layout and touch controls. There's more info on the forums here or you can get it on the Asset Store here!
Is there not a way to view LOGCAT from within the application itself? Isn't there a script debugging window that pops up when you have script debugging enabled for any PC deployment?