Debugging on the device

It is possible to retrieve debug logs, warnings, and errors from the device while the game is running. This comes in very handy in debugging, especially if you have unwanted behavior recurrent on the device and not in the editor's play mode.

We can retrieve these logs through the console, using logcat, which is a combined message pipe for all Android applications, as follows:

  1. Connect your device to the computer with USB debugging enabled.
  2. Launch the game on your device.
  3. Hit the Windows key + R to open the Execute window (or launch the Terminal on Mac and move directly to step 3).
  4. Type cmd in the new window and hit Enter or click on the Ok button.
  5. In the newly opened command window, type cd followed by your Android SDK's platform-tools folder location and hit Enter. For example, in my case it is:
    cd C:SDKplatform-tools
    

    Tip

    If your Android SDK isn't on the C: drive, you must request to change the current drive by entering the new drive letter followed by the : character. For example, if your SDK is on the D: drive, you have to first enter:

    d:
    

    Only then can you point to your SDK folder.

Good. You now have the following commands available to retrieve the game's logs:

  • adb logcat: This displays everything that's going on. You will be overwhelmed by the number of lines per second.
  • adb logcat –s Unity: This displays only the output from Unity.
  • adb logcat –s Unity > logcat.txt: This dumps logcat into the logcat.txt file in the platform-tools folder of your Android SDK. You must close the command window before you can open the logcat.txt file.

After entering adb logcat –s Unity, you should be able to find Debug.Logs() from our Play button's EventTester component, as shown in the following screenshot:

Debugging on the device

Great. Now that you know how to debug our game, we can summarize what you've learned in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.17.139