简体   繁体   中英

Android device and Unity connection failure

I'm trying to debug Unity game from PC with Windows 10 to Android phone:

  1. In Unity from File > Build Settings I've Switch Platform to Android
  2. In Android device I've downloaded and installed Unity Remote 5 application.
  3. In phone Settings/About phone with 7 taps on Build number I get Developer Options and turned on USB debugging and tap on Revoke USB debugging authorization
  4. In Select USB Configuration I've checked PTP (Picture Transfer Protocol)

I've checked 2 different USB cables with 3 different phones and each device is successfully detected and recognized by PC OS, Unity Remote says "Connect this device with a USB Cable to your computer. Press PLAY in the Unity Editor to test" , but Unity Editor by some reason does not shows any of my devices in Edit > Project Settings > Editor device:

在此处输入图片说明

edit:

I've downloaded both Android Studio and separately sdk-tools-windows-4333796.exe from Command line tools only .

First I've installed from Java SE Development Kit 8u241 jdk-8u241-windows-x64.exe for Windows x64

In Windows 10 OS Environment Variables/System Variables/Path , I've added C:\\Program Files\\Java\\jdk1.8.0_241\\bin and C:\\Program Files\\Java\\jre1.8.0_241\\bin

In User Variables I've added Variable name : JAVA_HOME and Variable value : C:\\Program Files\\Java\\jdk1.8.0_241\\bin

So, first I did not used sdk-tools-windows-4333796.exe and have installed Android Studio, here is what Edit > Preferences > External Tools shows:

在此处输入图片说明

Then, I've removed Android Studio and tried to use only sdk-tools-windows-4333796.exe , I've extracted tools folder to previously created folders path C:\\Android\\android-sdk , then from C:\\Android\\android-sdk\\tools\\bin load sdkmanager.bat with "platform;android-25" or "platform;android-26" argument, but error says:

Warning: File C:\\Users\\User.android\\repositories.cfg could not be loaded. Warning: Failed to find package platform;android-25 [===
] 10% Computing updates... C:\\Android\\android-sdk\\tools\\bin>

And finally I've tried install with Unity Hub:

在此处输入图片说明

but it same result, device does not appears in Editor, and External Tools shows checked:

在此处输入图片说明

and if unchecked:

在此处输入图片说明

I'm not quite sure, what I've missed or what I'm doing incorrectly

Any guide, advice or example would be helpful

For Unity Remote to work, you need to have the Android SDK on your development machine. Do you have it? If yes, then to specify the location of your Android SDK, go to Edit > Preferences. Unity Docs will help you.

To use Visual Studio 2019 to debug a Unity app running on an Android device connected to USB:

  1. Install Unity and Visual Studio 2019 (any edition including Community Edition). Verify in the Visual Studio installer that Game development with Unity is included.
  2. Set the Android device in Developer Mode. In Settings | About Tablet | Software Information, tab the Build number field 8 times. In Settings | Developer options: enable USB Debugging; enable Stay Awake.
  3. Make sure Visual Studio 2019 is the external tool used by Unity. This way, Unity will generate a solution file containing all script assets and .net packages. If you don't (and just open the editor based on the file extension), you don't get intellisense and no debugging when you start/attach the debugger. Use Edit | Preferences. 外部编辑
  4. Copy the Android SDK path from the version of Unity that you use for editing your current project, into Visual Studio. Copy the path from Unity "Edit | Preferences | External Tools | Android SDK Tools installed with Unity" to Visual Studio "Tools | Options | Tools for Unity | General | Preferred Android Sdk Root". This path is similar to this, depending your Unity version: "C:\\Unity\\2020.3.12f1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\SDK". Note that this is a critical step for the USB connected device to show up in Visual Studio. See also https://answers.unity.com/questions/1320966/android-debug-usb.html . SDK路径
  5. In Unity File | Build Settings, select Development Build, Script Debugging and Wait for Managed Debugger. 构建设置
  6. In the Unity Status Bar (bottom Right) enable Debug Mode. The bug icon needs to be yellow. 调试模式
  7. Build and Run from Unity. Wait for the android device to show the app with dialog “Debug | You can attach a managed debugger now if you want”.
  8. Open a C# Script from Unity, this opens the Visual Studio solution
  9. In Visual Studio, use Debug | Attach Unity Debugger to see the running instances. 在此处输入图片说明
  10. Select the USB device that is running the App and awaiting the managed debugger to connect. 选择设备

Place breakpoints in the code for single stepping and watching and inspecting variables as needed. 🎉

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM