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 /tools or*/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:
You find the Terminal.app under Applications / Utilities. cd to /tools (or /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.
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.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.
#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.
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).
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).
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.