VS debugging Android Unity application

I recently encountered a bug that needs to be debugged on an Android phone, so here is a record of how to use VS to debug Android applications. The VS I use is 2017, but the updated 2019 and other versions should be similar (after all, it actually relies on the Visual Studio Tools for Unity plugin). The Unity version is 2018.4 (LTS version), but later updated versions should be the same. Because I am debugging directly with the test machine connected to the computer, so the main content here is about debugging the Android Unity application on the test machine connected to the computer.

The first step, VS configuration

First, make sure that you can use VS to debug the Unity application, that is, the plug-in can be used normally and attached to the Unity process normally. Before debugging Android, you can try to attach to the Unity process on the computer. If there is no error, you can confirm that the plug-in can be used normally.

 

If there is no Attach to Unityoption for this, please install the corresponding plugin in the VS installer:

 

The second step, Unity open Debug package

 

Remember to check the packaging options Development Build, , Script Debugging, Wait For Managed Debuggerand the first two are mainly to ensure that it is Debug mode. The third option must be checked. After checking, the application will be paused before entering the application, allowing you to connect to the debugger first. Then enter the Unity application. Simply tap Build And Runto let the app run on your phone. If Run Deviceyou don't see your connected phone there, it may be that the phone has not turned on the debugging mode, and you should be able to see it if you turn it on.

The third step, run the application and debug it with VS

The previous steps are all preparatory steps, and the next step is the real important step.

If there are no problems with the previous settings, you should see this bullet box on the mobile app:

This is to prompt us that the debugger can be connected. After the connection is complete, we can click OKthe button to start the Unity application.

Next we look back to VS, we choose Debug- Attach Unity Debugger:

 

Then a pop-up box will pop up, select your phone:

 

Click OK, then change the startup items:

 

Remember the port above, and select the corresponding option.

After the configuration is complete, you can directly attach it. Click the button in the top application pop-up box OKto start the Unity application, and you should be able to trigger the breakpoint of VS. In addition, if you click Attach, but the VS interface does not turn orange, then the Attach was not successful, and VS may need to be restarted.

Guess you like

Origin blog.csdn.net/qq_42672770/article/details/128220527