Android device and Unity connection failure
Asked Answered
S

2

0

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:

enter image description here

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:

enter image description here

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:

enter image description here

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

enter image description here

and if unchecked:

enter image description here

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

Any guide, advice or example would be helpful

Stalinist answered 18/2, 2020 at 2:23 Comment(2)
why you don't try ADB tool for debug or scripting debug for direct android device ?Amerind
@Amerind Hello, I've added additional information on my task, please checkStalinist
G
1

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. External Editor
  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 Path
  5. In Unity File | Build Settings, select Development Build, Script Debugging and Wait for Managed Debugger. Build Settings
  6. In the Unity Status Bar (bottom Right) enable Debug Mode. The bug icon needs to be yellow.Debug Mode
  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. enter image description here
  10. Select the USB device that is running the App and awaiting the managed debugger to connect. Select device

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

Guileless answered 29/6, 2021 at 14:25 Comment(0)
E
0

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.

Erotic answered 18/2, 2020 at 13:15 Comment(1)
Hello, sorry for late replay. I've added additional information on my attempt, following your answer, please check, but it seems like something goes wrongStalinist

© 2022 - 2024 — McMap. All rights reserved.