Home > Back-end >  Cannot get neither the Android Emulator nor Run project to device working in Xamarin
Cannot get neither the Android Emulator nor Run project to device working in Xamarin

Time:01-21

I am using a brand new xamarin.forms solution generated with the flyout shell template in VS 2022 community edition.

When I open the emulator and follow the first time setup, where it generates a common android device I get this error when trying to launch the emulator. I also get this error when creating a device myself.

Unknown AVD Name Error <- This part has been fixed by setting the ANDROID_SDK_HOME variable to the correct directory in the Environment Variables in system settings. But the emulator can still not be used for debugging.

I have tried looking around for solutions on all sorts of forums to get the emulator to work, but didn't find anything that made a difference.

I have tried running on a local device using USB instead as it was suggested that it was easier to get to work then the emulator, which didn't work either. The device does not show up in the Android Emulator drop-down menu. I then tried different cables and it still did not show up as a detected device.I then tried via wireless connection just in case something was up with the cables. It still doesn't show up. But if I check the devices through the adb command prompt I can see the device is connected and authorized, both when using the cable and when using the wireless connection. And the computer itself detects the device just fine.

  • The Device is in developer mode.
  • USB debugging is on.
  • The computer is approved as a trusted device.
  • Android project is set as start up project.
  • SDK's and tools have been downloaded using the Android SDK manager.
  • USB drivers have been downloaded for the device.

I have already tried

  • closing and opening VS multiple times.
  • Unloading and reloading the project.
  • Setting the device to PTP mode instead.
  • Reinstalling VS including deleting and regenerating the Java and Android folders.
  • Uninstalling VS 2022 and trying 2019 instead.
  • Generating a new VS solution.
  • downloading and installing the JDK manually.
  • Seeing that Virtual emulation is on in the BIOS.
  • Making sure the system is able to run Hyper-V and that it is on.
  • checking that the folder paths are set correctly in the options menu.
  • Making sure all nuget packages are up to date.

Any suggestions would be highly appreciated as I cannot debug and test the device properly at the moment.

CodePudding user response:

If you see an error about a failure to install the APK on the emulator or a failure to run the Android Debug Bridge (adb), verify that the Android SDK can connect to your emulator. To verify emulator connectivity, use the following steps:

Launch the emulator from the Android Device Manager (select your virtual device and click Start).

Open a command prompt and go to the folder where adb is installed. If the Android SDK is installed at its default location, adb is located at C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe; if not, modify this path for the location of the Android SDK on your computer.

Type the following command:

adb devices

If the emulator is accessible from the Android SDK, the emulator should appear in the list of attached devices. For example:

List of devices attached
emulator-5554   device

If the emulator does not appear in this list, start the Android SDK Manager, apply all updates, then try launching the emulator again.

Update:

you can open the Android Device Manager first.

Select the device you want to run and click the Start button, so that the virtual machine can be started and detected, and then your virtual machine The device will be added to the Android Emulators menu.

CodePudding user response:

I ended up wiping the hard-drive and starting from scratch. This time all I had to do was install VS and enable Hyper-v and everything worked as it should right away.

I have absolutely zero idea what caused this issue, but a complete wipe fixed it.

  •  Tags:  
  • Related