Matt Gregory
Matt Gregory

Reputation: 8682

Cannot debug Xamarin app in Visual Studio Android emulator

I'm trying to learn Xamarin, but something happened to my setup and I can no longer open my app inside the emulator by clicking the Debug/Run button. All it does is open or activate (if it's already open) the Android Device Manager.

The Visual Studio output window (Build) states:

The debug was canceled. Please create an android emulator to debug the application.

I've created an emulator and it works. The emulator is running when I try to run my app.

Also, a message box pops up in the Android Device Manager that says:

Device Manager

Device error: error: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.

I don't know what any of this means and I can't find the documentation that covers this.

'adb kill-server' doesn't have any effect. I've tried that command in the adb command prompt, and I've manually started up an admin command prompt and tried killing and restarting adbd. I've tried regenerating keys with 'adb keygen', but I can't anything to have any effect.

I'm on Windows 10.

The Xamarin Diagnostics window looks like this after I start VS, click Run, the Android Device Manager opens with the create new emulator dialog, I cancel out of that and run the emulator I already created, I wait for it to boot and then I click Run again, which just brings the ADM window forward.

[D:]:                     FindVersionFile: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Version, result=False
[D:]:                     FindVersionFile: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Version.txt, result=True
[I:]:                     Found Xamarin.Android 9.3.0.23
[I:sdk]:                  Runtime path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android
[I:sdk]:                  Framework path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0
[D:]:                     ValidateAndroidSdkLocation: `C:\Program Files (x86)\Android\android-sdk`, result=True
[D:]:                     ValidateAndroidNdkLocation: ``, result=False
[I:]:                     Looking for Android NDK...
[I:]:                     Looking for Android SDK...
[D:]:                     ValidateAndroidSdkLocation: `C:\Program Files (x86)\Android\android-sdk`, result=True
[D:]:                     ValidateAndroidSdkLocation: `C:\Program Files (x86)\Android\android-sdk`, result=True
[D:]:                     ValidateJavaSdkLocation: `C:\Program Files\Android\Jdk\microsoft_dist_openjdk_1.8.0.25`, result=True
[I:]:                     Tracking android devices started
[D:]:                     Tracking avd started
[D:]:                     avd watcher *.ini path: 'C:\Users\Matt\.android\avd'
[D:]:                     avd watcher: got device list from avd with 0 devices
[D:]:                     TrackDeviceTask got: 
[I:]:                     Got new device list from adb with 0 devices
[I:]:                     Looking for Android SDK...
[D:]:                     ValidateAndroidSdkLocation: `C:\Program Files (x86)\Android\android-sdk`, result=True
[D:]:                     ValidateAndroidSdkLocation: `C:\Program Files (x86)\Android\android-sdk`, result=True
[D:]:                     TrackDeviceTask got: emulator-5554    offline
[I:]:                     Got new device list from adb with 1 devices

Edit: I've found the device log, courtesy of the User Account Control window that pops up when I click the Run button without the Android Device Manager window open and it opens the ADM. The origin of the error is shown in the relevant part of the log:

[19-08-10 23:56:44.17] Executing command: "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" "-s" "emulator-5554" "shell" "getprop" "emu.uuid"
[19-08-10 23:56:44.21] C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe result: 
StandardError: error: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.
ExitCode: 1

Upvotes: 4

Views: 6474

Answers (4)

Felice Ferri
Felice Ferri

Reputation: 41

Launching Visual Studio as an administrator solved it for me.

VS 2022 17.5.3 Xamarin 17.5.0.173 Xamarin.Android.SDK 13.2.0.0

Upvotes: 0

Abhi
Abhi

Reputation: 36

Here is the solution:

Visual Studio -> Tools -> Get Tools and Features -> Visual Studio Installer -> Modify -> Individual Components -> scroll down for "SDKs, libraries, and frameworks" -> select Android SDK setup (API level 30) and (API level 25) -> Modify.

View in screenshot

Upvotes: 0

user14321699
user14321699

Reputation:

I had this issue as well and deleting the device and creating a new one seemed to resolve my issue. I'm not sure if it's a permanent fix but it resolved mine so I thought I'd share this. You can do so by right clicking on the device in the Android Device Manager and clicking delete.

Upvotes: 1

Matt Gregory
Matt Gregory

Reputation: 8682

I fixed it!

I went into the Android SDK Manager and uninstalled everything, all platforms and tools. It wasn't able to uninstall the "Android SDK Platform 28" because of some kind of access denied error, so I rebooted thinking it would free up the SDK for deinstallation, but I realized that starting VS in order to uninstall would lock it up again (and I didn't feel like figuring out what the Android SDK Manager executable would be to start it without VS), so I went into the VS installer and removed the whole "Mobile Development with .NET" category, then I reinstalled it. I then went into the Android SDK Manager and installed the Android Emulator 29.0.11 and it works now.

Upvotes: 1

Related Questions