Anton Nel
Anton Nel

Reputation: 321

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!

Upvotes: 6

Views: 14266

Answers (4)

Petr Varyagin
Petr Varyagin

Reputation: 287

  • Menu "Window-Package Manager"
  • Install "Android Logcat"
  • Then menu "Window-Analasys-Android Logcat"

The device must be connected via USB. Development mode and USB debugging must be enabled on device

Upvotes: 6

Joel Carneiro
Joel Carneiro

Reputation: 11

You can use the Android Monitor Device from your SDK/tools folder.

  • Go to the logCat tab.
  • Now you need to make a filter by the "Unity" tag.
  • And then when you connect your Android device to your PC, you can see the logs using your filter.

If you want you can see my tutorial:

https://youtu.be/55rkbsjhA3U

Upvotes: -3

peterept
peterept

Reputation: 4427

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

Upvotes: 11

Plastic Sturgeon
Plastic Sturgeon

Reputation: 12527

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([email protected]: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:

Upvotes: 4

Related Questions