Search code examples
c#androidloggingunity-game-engineapk

How to log in a Unity android game?


Sorry for the noob question, but how to I view logs when I have built the game as an .APK on an Android device? I know how to view Debug.Log (in the Unity console), but not on Android. If there is something else than Debug.Log, what is it? I just need to log some lines in my script while it is running on an Android device(NOT EDITOR) since I'm having issues with Google Play Leaderboard login.

Thank you so much!


Solution

  • Debug.Log on Android logs to the system log. Which you can view via $ adb logcat command.

    Unity Reference: Log Files

    Plug in your Android phone via USB cable. Open up Terminal and change folder to your Android SDK platform-tools folder, then run:

    $ adb logcat
    

    or, to filter only on Unity messages (if you are on mac/linux):

    $ adb logcat | grep -e "Unity" 
    

    Once you have the phone plugged into USB, you can also use adb to switch it over to Wifi.

    But alternatively I also wrote a script for Android to route all Debug.Log over Wifi to a TCP listener. It's one script to add to your scene:

    Unity3D Debug Logs over WiFi