Testing in Unity Editor is simple. All errors are visible either in Unity console log or in Visual Studio log. However, Unity editor emulator does not need to reflect real app behaviour and performance perfectly + not all features are available for running in the Unity editor - from this reason usage of these logs is limited. If you have unspecific device-related problem or you use any platform-specific conditions in your app (e.g. #if UNITY_ANDROID) or 3rd party service such as Google AdMob or some from Google Play Services which work on mobile device only (after build), you will find out need to have option to check logs generated also during running your app in the target device (not in emulator like Unity editor). This article will provide you simple step by step walkthrough to achieve this.
1. Target device
Debugging may go over USB cable or Wifi. Process to enable USB debugging is described in point Android device configuration.
2. Required tools
Debugging on Android mobile device is available via Android Debug Bridge, shortly ADB. Android Debug Bridge is a command line tool installed to PC together with Android SDK package. If Android Debug Bridge (ADB) was set as a global variable (like e.g. JAVA_HOME variable in Unity configuration), then adb can be accessed from any location in command line (cmd). If it is a local variable, the adb is accessible from subfolder "platform-tools" located in installation folder of Android SDK. "adb.exe" is name of the file you are interested for.
Access log of app made with Unity is accessible by opening "adb logcat -s Unity". This will print log to your command line in a real-time. For downloading older log from your device, check all options in Android Debug Bridge documentation.
3. Unity Build Settings
Android bridge is active for Unity content running on android device only. Going to Unity play mode is not sufficient, the app must ve properly built and installed in the Android device. Android build settings does not require any special adjustments.
There is fully sufficient to have connected Android device with your PC and in build settings let "Run Device" option on "Default device", alternatively you can select specific or all device(s) if you have more Android devices connected to your PC. There is no need to do development builds or anything so.
Quick step-by-step conclusion
- Connect your Android device to PC
- Make an Android Build and launch it on your device
- In command line, activate displaying log from Unity by requesting "adb logcat -s Unity". (adb is accessible from folder with installed Android SDK (subfolder "platform-tools")
- Now you see all Unity logs related to Unity in real-time.