Anton Nel February 2016

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!

Answers


Plastic Sturgeon February 2016

You'll want to use the Unity Profiler. http://docs.unity3d.com/Manual/Profiler.html

You can connect over local wifi, or usb to debug an app on android, ios, or PC.

The unity docs at the link describe the steps.

But in case that page moves:

For WiFi profiling, follow these steps:

  • Make sure to disable Mobile Data on your Android device.
  • Connect your Android device to your WiFi network.
  • Attach your device to your Mac/PC via cable, check the “Development Build” and “Autoconnect Profiler” checkboxes in Unity’s build settings dialog, and hit “Build & Run” in Unity Editor.
  • When the app launches on the device, open the profiler window in Unity Editor (Window->Profiler)
  • If the Unity Editor fails to autoconnect to the device, select the appropriate device from the Profiler Window Active Profiler drop down menu. Note: The Android device and host computer (running the Unity Editor) must both be on the same subnet for the device detection to work.

For ADB profiling, follow these steps:

  • Attach your device to your Mac/PC via cable and make sure ADB recognizes the device (i.e. it shows in adb devices list).
  • Check the “Development Build” checkbox in Unity’s build settings dialog, and hit “Build & Run”.
  • When the app launches on the device, open the profiler window in Unity Editor (Window->Profiler)
  • Select the AndroidProfiler(ADB@127.0.0.1:54999) from the Profiler Window Active Profiler drop down menu. Note: The Unity editor will automatically create an adb tunnel for your application when you press “Build & Run”. If you want to profile another application or you restart the adb server you have to setup this tunnel manually. To do this, open a Terminal window / CMD prompt and enter:


peterept February 2016

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

Post Status

Asked in February 2016
Viewed 3,672 times
Voted 8
Answered 2 times

Search




Leave an answer