Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Any tips for debugging Android?

Discussion in 'Android' started by DaveA, Dec 9, 2010.

  1. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    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
     
    wstelzle and ozgurdugmeci like this.
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    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.
     
  3. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    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?
     
    Last edited: Dec 9, 2010
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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.
     
    Last edited: Dec 10, 2010
    crobertson likes this.
  5. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    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.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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.
     
  7. George S

    George S

    Joined:
    Jul 28, 2009
    Posts:
    54
    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):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class GuiTextDebug : MonoBehaviour {
    7.  
    8.     private float windowPosition = -440.0f;
    9.     private int positionCheck = 2;
    10.     private static string windowText = "";
    11.     private Vector2 scrollViewVector = Vector2.zero;
    12.     private GUIStyle debugBoxStyle;
    13.    
    14.     private float leftSide = 0.0f;
    15.     private float debugWidth = 420.0f;
    16.    
    17.     public bool debugIsOn = false;
    18.    
    19.     public static void debug(string newString)
    20.     {
    21.         windowText = newString + "\n" + windowText;
    22.         UnityEngine.Debug.Log(newString);
    23.     }
    24.        
    25.     void Start () {
    26.         debugBoxStyle = new GUIStyle();
    27.         debugBoxStyle.alignment = TextAnchor.UpperLeft;
    28.         leftSide = 120; //Screen.width - debugWidth - 3;
    29.     }
    30.        
    31.    
    32.     void OnGUI () {
    33.        
    34.         if (debugIsOn) {
    35.  
    36.             GUI.depth = 0;
    37.                        
    38.             GUI.BeginGroup (new Rect(windowPosition, 40.0f, leftSide, 200.0f));
    39.            
    40.                 scrollViewVector = GUI.BeginScrollView (new Rect (0, 0.0f, debugWidth, 200.0f), scrollViewVector, new Rect (0.0f, 0.0f, 400.0f, 2000.0f));
    41.                 GUI.Box (new Rect (0, 0.0f, debugWidth - 20.0f, 2000.0f), windowText, debugBoxStyle);
    42.                 GUI.EndScrollView();
    43.            
    44.             GUI.EndGroup ();
    45.            
    46.            
    47.    
    48.             if (GUI.Button(new Rect (leftSide, 0.0f,75.0f,40.0f), "Debug")){
    49.                 if (positionCheck == 1){
    50.                     windowPosition = -440.0f;
    51.                     positionCheck = 2;
    52.                 }
    53.                 else {
    54.                     windowPosition = leftSide;
    55.                     positionCheck = 1;
    56.                 }
    57.             }
    58.            
    59.             if (GUI.Button(new Rect (leftSide + 80f,0.0f,75.0f,40.0f),"Clear")){
    60.                 windowText = "";
    61.             }
    62.         }
    63.     }
    64.  
    65.  
    66. }
    67.  
     
    CedricKnapp, li3ro and EnriqueL like this.
  8. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    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?
     
  9. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    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.
     
  10. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    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?
     
  11. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    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).
     
  12. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    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.
     
  13. dreammakersgroupAdmin

    dreammakersgroupAdmin

    Joined:
    Feb 13, 2012
    Posts:
    40
  14. mushroomrisotto

    mushroomrisotto

    Joined:
    Dec 9, 2013
    Posts:
    24
    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/
     
  15. ysrikanth2011

    ysrikanth2011

    Joined:
    Sep 6, 2013
    Posts:
    3


    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 .
     
  16. shaarptooth

    shaarptooth

    Joined:
    Apr 30, 2014
    Posts:
    6
    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.
     
    Marzoa likes this.
  17. shaarptooth

    shaarptooth

    Joined:
    Apr 30, 2014
    Posts:
    6
    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
     
    MapuHoB likes this.
  18. Marzoa

    Marzoa

    Joined:
    Dec 2, 2012
    Posts:
    50
    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.
     
  19. lakeman

    lakeman

    Joined:
    Jun 15, 2015
    Posts:
    1
    Last edited: Mar 24, 2016
  20. Chetim

    Chetim

    Joined:
    Jan 30, 2013
    Posts:
    12
    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.
     
  21. Inf1nite

    Inf1nite

    Joined:
    Dec 1, 2012
    Posts:
    4
    UnityVS allows remote debugging via Android within Visual Studio.
     
  22. faraz

    faraz

    Joined:
    Aug 4, 2014
    Posts:
    46
    when i entered adb logcat i got this lines comming.

    Code (CSharp):
    1. adb server is out of date.  Killing.
     
  23. dabeku

    dabeku

    Joined:
    Oct 13, 2015
    Posts:
    1
    [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

    Loginator.png
    Configuration.png

    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.
     

    Attached Files:

  24. IndieFist

    IndieFist

    Joined:
    Jul 18, 2013
    Posts:
    518
    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?)
     
  25. robinwood

    robinwood

    Joined:
    Dec 2, 2015
    Posts:
    18
    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 :)
     
    Last edited: Mar 28, 2016
  26. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    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):
    1. 04-02 15:58:02.084: W/Unity(18048): UnityEngine.Logger:LogFormat(LogType, String, Object[])
    2. 04-02 15:58:02.084: W/Unity(18048): UnityEngine.Debug:LogWarningFormat(String, Object[])
    3. 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...
     
    AlexWei and username132323232 like this.
  27. apkpure

    apkpure

    Joined:
    Apr 6, 2016
    Posts:
    3
    Thats great
     
  28. Chrisjordan

    Chrisjordan

    Joined:
    Sep 29, 2016
    Posts:
    3
    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
     
  29. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    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.
     
  30. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    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!
     
  31. jolasman

    jolasman

    Joined:
    Mar 7, 2018
    Posts:
    1
    I have a solution in my new video :)

     
    AlexWei likes this.
  32. ghostravenstorm

    ghostravenstorm

    Joined:
    Oct 18, 2015
    Posts:
    88
    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?