How to debug Unity using a mobile phone (real device)

Mobile phone operation

First turn on the "USB debugging" switch on your phone.

Specific steps

Here we take a Huawei mobile phone as an example. The system of the mobile phone is EMUI10. The specific operation is as follows:
first open the mobile phone > enter "Settings" > find "About Phone" > click "Version Number" continuously, and then stop when prompted to enter developer mode. This way we enter developer mode.
Then go to "System and Updates" > Select "Developer Options" > Scroll down. Within the debugging list, there is a "USB Debugging" switch. Turn this switch on.
Please add image description
At the same time, select the USB connection method. Here we choose "Transfer Files". Note that files must be transferred!

Please add image description

Unity operation

After setting up the mobile phone, we enter Unity, select "File"> in the menu bar and then select "Build Settings...".
Please add image description
In the Build Settings window, select "Android" for Platform on the left, and select your phone for "Run Device" in the Android panel on the right. If it does not appear, click the Refresh button next to it.
Please add image description
Then click Build And Run, which will ask you to select a folder to store the APK, and an installation prompt will automatically pop up on your phone. After installation, you can run the project on your real machine.

Error handling

No phone detected

Click on your computer's resource file manager to see if there is a disk on your phone. If there is no mobile phone disk, it may be that your mobile phone has not turned on "Transfer Files (MTP)", but has selected "Charging Only" or "Transfer Pictures (PTP)". Note that it is not possible to transfer pictures, and must be transferred. document.
If your mobile phone does not pop up the option of "Transfer Files" or "Charge Only", then you need to check your USB cable. Some USB cables only support charging and do not support file transfer. Change to some USB data cables. Try it.
Generally speaking, the USB cables of mobile phone chargers support file transfer, while the USB cables provided by some non-mobile devices only support charging, such as the charger that comes with a wireless mouse. So when you use a USB cable, you should choose a mobile phone charging cable.

おすすめ

転載: blog.csdn.net/weixin_44499065/article/details/131738727