How to log in a Unity android game?
Solution 1
Debug.Log on Android logs to the system log. Which you can view via $ adb logcat
command.
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:
Solution 2
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:
Solution 3
- 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
Anton Nel
Updated on June 04, 2022Comments
-
Anton Nel almost 2 years
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!
-
Fattie about 8 yearsI think it's a good question! But it's possible it will be closed on here as it is not about "code" as such.
-
-
Fattie about 8 yearsPlastic, you're sure the
Profiler
shows log messages? If so where, thanks for the tip. -
Anton Nel about 8 yearsSumbled on this after a quick Bing search: answers.unity3d.com/questions/32368/… so looks like it is worth a shot... will try tomorrow.
-
Fattie about 8 yearsWow @peterept that looks crazy impressive script! One question, TBC you're saying the process you describe in the first six lines works on a Mac even? cheers
-
Anton Nel about 8 yearsSo to use $ adb logcat I simply put that in a c# script in my app or what? I found the adb.exe in the android SDK tools
-
Plastic Sturgeon about 8 years@JoeBlow - You're right. No log messages. The answer from peterept above seems to answer the specific question better. Android studio and LogCat might also work.
-
Fattie about 8 yearshey thanks for that, it's a great help. this answer is still very useful to googlers ... (perhaps you should just edit in a word that it doesn't specifically bring up the logs, in this version of Unity anyways). Now, about my nose job...
-
Fattie about 8 yearsHi @AntonNel ... on your mac, click
SpotlightSearch
(loupe at extreme top right of physical Mac screen), type inTerminal
, launch that. if you're not familiar with a shell, that's what that is (example, typels
ordate
. PeterEpt is suggesting commands to thus type in toTerminal
(ie, the unix shell of your Mac ... it's really just a unix box with some stupid interface crap on top - that's why they work so well these days). -
Anton Nel about 8 yearsAnd on Windows 10? I'm on Windows since I built my own PC, I'm sure there is a Terminal equivalent since Windows is supposed to have more software available than Mac. Thanks for the help!
-
Anton Nel about 8 yearsI tried to use $ adb logcat in the command prompt (cmd.exe) but it didn't recognize it
-
peterept about 8 yearsahhh you are on windows? you open up command, then go to your platform tools, eg:
c:
cd \android\sdk\platform-tools
then runadb logcat
. -
peterept about 8 yearsAlso if you are not sure the Android SDK location, look inside your Unity settings - it will be listed there.
-
Anton Nel about 8 yearsTHANK YOU! I did win+R (open run) then cmd.exe (command prompt). Once the Command Prompt was open I navigated to the sdk folder using cd .. (to go up a folder) and cd to open a folder. Then once I was in
C/Program Files (x86) \Android\android-sdk\platform-tools
I typed in adb logcat and it says "waiting for device". Looks like it is working! -
Anton Nel about 8 yearsAlso can I filter the logcat so it shows just the logs from my app? Because currently it is showing hundreds of lines per second making it useless
-
peterept about 8 yearsYes, use
adb logcat -s Unity