Android debugging with Unity
by Harry Jackson (Upwardbinkie)
Hello there!
If you’re reading this, it’s probably because you’re making a game for Android and are having trouble debugging it from your device. In that case, you’re in luck as we’re about to share exactly how we do it.
Preparing the Android device
First you’ve got to make sure you have Developer Settings enabled on your Android device so that you can enable USB debugging.
- On the Android device navigate to Settings > System > About Phone, scroll down and tap Build Number seven times. You’ll see a message saying that “You are now a developer!”.
- Navigate to the now available Developer Options, scroll down and enable USB Debugging.
- That’s it, now you can start debugging on your device.
Running the game on your Android device
If you haven’t done so already, connect your device to your computer and make sure USB Debugging is enabled. Then, in Unity, go to File > Build Settings, click the Refresh button next to the Run Device option and then select your device. Lastly, click Build And Run.
This will generate an APK on your computer that will then get installed automatically on your device.
Debugging your game
Finally, in your computer, open up the command console and navigate to the Android Player SDK platform tools:
> cd C:\Program Files\Unity\Hub\Editor\2021.1.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools
* Make sure your the path matches the unity version installed in your computer.
Type adb and press Enter to initialize the Android Debug Bridge.
Finally, type adb logcat -s Unity to start debugging your Android game.
As you can see, when we debug our game Pafu (Available on the PlayStore), the log shows our debug messages and lists the involved methods, making it very easy to identify what classes or methods are not behaving as expected.
Too much typing?
Yes, that’s too much typing. That’s why I have this handy little batch file on my desktop always ready for when I need to debug my Android games. This is not necessary but is a bit helpful. Feel free to fork or copy it :D
Happy debugging!
I hope you find this method as useful as we do, and while this method might not solve all your problems or bugs, it sure is a good way to start looking into what’s causing them.
Cheers!