Debugging with Android Debug Bridge
Ashley Kwon (Spring 2023)
Android debug bridge (ADB) is a useful tool that you can use to debug your Unity project, especially if you are using C# scripts. ADB helped me detect bugs that only occur when I run my apps on an Oculus headset, which are often difficult to spot simply by running the apps through the Unity editor on my desktop. To use this debugging tool, you need the following:
Download link: Download Android Studio & App Tools - Android Developers
Oculus desktop app (Developer mode enabled)
Install Android Studio using the link above. Make sure to remember the download location on your computer.
While your headset is turned on, connect it to your computer (you can use either Oculus Link or Oculus Air Link), and open your Oculus desktop app to make sure that your headset is connected. You may need to allow your computer to access your headset through a dialog shown in your headset.
Open your terminal and navigate into the location you downloaded Android Studio. Then, navigate into the folder that contains adb.exe
In your terminal, type the comment below. You should your headset listed under "List of devices attached"
In your Unity project, open the C# you want to debug. Then use Debug.Log to write statements that should or should not be printed if your app runs correctly. For example, I used the following Debug.Log statement to test whether my right hand controller works correctly.
6. In your terminal, type the following statement, but don't run it yet. debuggingLog is the name of the text file where the log that results from running your Unity app, including Debug.Log statements, are printed. Please feel free to replace debuggingLog to another name that easier for you to identify.
adb.exe logcat > debuggingLog.txt
7. Build and run your Unity app through Unity editor.
8. Once the app starts running in your headset, run the statement you typed in 6.
9. When you finish running your app in your headset, stop the command that is currently running in your terminal using command + C or ctrl + C. This will ensure that no other statements get printed in your text file when your app is not running.
10. Navigate to the folder where you created your txt file and open the file. Use command + F or ctrl + F to find the Debug.Log statement(s) you wrote in your C# file. In the example from 5, if my app successfully accessed my right joystick whenever I moved it, the txt file should contain lines that read "right joystick triggered"