4

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
Matt Gregory
  • 8,074
  • 8
  • 33
  • 40
  • Visual Studio Android Emulator? Is it that old one that they distributed at some point with very limited amount of images you could use? How about trying the emulator that comes with the Android SDK? – Cheesebaron Jun 30 '19 at 20:38
  • @Cheesebaron I believe it is the emulator from the SDK, but I'm not entirely sure. How do I find out? The emulator version is 28.0.25-5395263 (HAXM 6.2.0) – Matt Gregory Jun 30 '19 at 23:24
  • See [here](https://learn.microsoft.com/en-us/xamarin/android/get-started/installation/android-emulator/device-manager?tabs=macos&pivots=windows) to know how to create a new Android emulator. – nevermore Jul 01 '19 at 01:47
  • @JackHua-MSFT You're not helping, man. – Matt Gregory Jul 01 '19 at 11:34
  • See [this thread](https://stackoverflow.com/questions/31638582/android-adb-devices-unauthorized) about your problem. Seems it is related to the USB debugging Authorization. I give you the link in my last comment to help you to check if the emulator you created comes with the Android SDK. – nevermore Jul 02 '19 at 06:08
  • @JackHua-MSFT Fair enough, but none of that has any effect. The emulator was installed with the Android SDK Manager in Visual Studio. I am missing abdkey.pub in the .android folder. Is there any way to create one from the private key file? I don't know if that will fix it because I did have one when it stopped working. – Matt Gregory Jul 02 '19 at 20:42
  • What happens when you create another emulator and try to load that? Also, can you re install VS? – Saamer Jul 02 '19 at 21:34
  • @Saamer I've tried that...no effect. I just tried uninstalling/reinstalling... no effect. I tried deleting the entire.android directory, that didn't help. – Matt Gregory Jul 03 '19 at 02:17
  • Is this VS 2019 on a Mac? – Saamer Jul 03 '19 at 02:26
  • @Saamer Nope, Windows 10. Sorry, I should have put that in the original post. – Matt Gregory Jul 03 '19 at 02:40
  • Could you share more details of the Output when you are trying to upload. More lines in the window – Saamer Jul 03 '19 at 18:00
  • @Saamer There is no other output in the Build window. I posted the Xamarin Diagnostics window above. – Matt Gregory Jul 04 '19 at 00:24
  • You can try to follow the steps [here](https://stackoverflow.com/a/42052776/10539446) to create the abdkey.pub in the .android folder. – nevermore Jul 04 '19 at 08:29
  • @JackHua-MSFT The keygen command doesn't create the adbkey.pub file. In order to test this fully, I ran VS as Admin so that the adb cmd would open as Admin, and lo and behold, the emulator works. My emulated device shows up in the Debug button right when VS opens. I did not have to run VS as Admin before. What do you think changed? – Matt Gregory Jul 05 '19 at 15:54
  • Actually, it doesn't work. It gets stuck on "2>Waiting for runtime checks to complete" in the Build output window. The emulator is running, but the app doesn't pop up. – Matt Gregory Jul 05 '19 at 19:20
  • @JackHua-MSFT I fixed it. Thank you for your help! – Matt Gregory Jul 10 '19 at 14:43
  • Glad to hear that! You can mark your solution as an answer. – nevermore Jul 11 '19 at 01:21
  • @JackHua-MSFT It turns out reinstalling the SDK only fixes the problem temporarily. I keep running into this problem. – Matt Gregory Aug 11 '19 at 00:04

4 Answers4

1

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.

Matt Gregory
  • 8,074
  • 8
  • 33
  • 40
  • Turns out this is just a temporary fix. I have to de- and reinstall the Android SDK over and over again because this problem keeps happening. – Matt Gregory Aug 11 '19 at 00:03
1

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.

0

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

Abhi
  • 36
  • 3
0

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

Felice Ferri
  • 41
  • 1
  • 3