I got a new laptop this week (Win10), installed Visual Studio 2015 community, followed by Xamarin. I've created a blank Android project, uncommented the SetContentView(...) line in MainActivity.cs, then build the solution. However I'm running into various problems when I try to run it:
The list of emulators (next to the green "run" button) only contains two entries: "Android_accelarated_x86 (Android 6.0 - API 23)" and "Android_ARMv7a (Android 6.0 - API 23)". Is this normal? The Xamarin doc'n seems to suggest that a number of "Xamarin xxx" emulators would be installed.
When I run the project against "Android_accelarated_x86", the emulator starts up, Visual Studio reports the deployment is successful, but Visual Studio stops debugging. In the output window I see this:
InspectorDebugSession(0): StateChange: Start -> EntryPointBreakpointRegistered
InspectorDebugSession(0): Constructed
Android application is debugging.
Couldn't connect to logcat, GetProcessId returned: 0
InspectorDebugSession(0): HandleTargetEvent: TargetExited
InspectorDebugSession(0): Disposed
If I hit run again, the app seems to start on the emulator, but then a message appears saying "Unfortunately xxx has stopped" (where xxx is my project name). The above messages appear in the VS windows again (apart from the one about 'Couldn't connect to logcat...').
I've also noticed that the "Manage Virtual Devices" item in the dropdown is greyed out, so I presumably can't try creating a different emulator?
Shooting from the hip on this one but do you have the Android SDK installed? It should install a number of other emulators and give you access to the device manager.
There are emulators you can INstal with Visual Studio. Emulators that come with the Android SDK and emulators that install with Xamarin Studio.
One additional thing to try would be to install Xamarin Studios. It does a slightly better job in my experience of setting up your environment then VS Does.
Firstly, the Manage Virtual Devices is referring to Xamarin Android Player VMs (which is now deprecated). We're working on getting this removed if Xamarin Android Player isn't present.
To create / edit / fix your Google AVD VMs you should select Android Emulator Manager. Regarding the number of devices listed, I'd probably ensure everything Xamarin is updated..
Visual Studio > Tools > Options > Xamarin > Other > Check for Updates
..and also update all your SDK components. If you have an Intel CPU you should use the x86 images for best performance. If you haven't already installed this you can get it here:
https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager
If you update any images it could be that your AVD needs repairing, which you can do in the Android Emulator Manager by selecting the relevant image and clicking Repair.
Also, you will only be able to deploy to devices that your project is targeting, so it's worthwhile checking the AndroidManifest.xml or by right-clicking your project and checking the 'minimum' and 'target' Android API levels to ensure you're encompassing the AVDs you have created.
Related
I am new to Xamarin. I used Xamarin. Forms template to create a sample mobile solution in Visual Studio 2017. The process created four projects Xamarin PCL, Xamarin Android, Xamarin.iOS and Xamarin.UWP. Without making any modification to the generated solution, I am trying to run it.
The first issue is, when I set the UWP as the starting project, the Windows emulator shows up and runs the app perfectly. But when I try to do the same with Android, I get different errors at different times based on the environment changes I make. Finally, using the visual studio android emulator, the Phone UI shows up but not my app. In the background, I can see that Visual Studio completed the build process successfully without any errors but the deploy process simply hangs. I left the deploy running overnight but still running in the morning. Here is my environment.
Intel Core i7 processor
Virtualization enabled in BIOS
Windows 10 Education
32GB RAM
Hyper-V disabled in Windows
Executed bcdedit /set hypervisorlaunchtype off in the command window and rebooted.
I tried setting the above environment in different combinations but none of them seem to make the app work. When I use an android emulator from android SDK, the build process throws errors. The only emulator that even builds is the visual studio emulator. But the deploy hangs.
A second issue I have is, I have installed android SDK for version 24 and 25. But in the emulator dropdown, I can only see the emulators for 23. I checked the installation path both in visual studio and android SDK manager and they both point to the same installation folder. What do I need to make the emulators for version 24 and 25 usable?
I repeat, I did not make any change to the generated solution in visual studio before running it. I have been at it for the past three days and couldn't make it work. Please help.
I just installed Visual Studio 2017 (on Win10 15063.138) and found, like you, Xamarin projects won't deploy to Android. Here's how I got running:
Updated everything in the Android SDK Manager.
Installed the new, improved Android Emulator from MS:
https://www.visualstudio.com/vs/msft-android-emulator/
Used that to download/install an API level 23 (6.0 Marshmallow)
emulator
Started that emulator using the same tool (you'll see it running in Hyper-V Manager)
Selected same emulator in VS for deploy/debug (the emulators that ship with VS are painfully slow)
In VS, selected Android project for start-up and verified build and deploy to Android in build config mgr.
Note: MS doesn't appear to have any emulators above API level 23, so Compilation and Target settings for your Android project can be the latest, but the minimum target will have to be 6.0 (API 23).
After pulling my hair for the past few days, I finally got my Xamarin.Forms Android App to show my page on the emulator. Thanks to all the members for their suggestions. Ryan's suggestion helped a lot ( I +1ed him, thanks Ryan) but did not solve my problem. I googled further and found a suggestion that asked to change the following setting which did it for me finally. So, if anyone else get stuck like I did, please do the following (in addition to cleaning up and updating all packages):
Open up the setting for your Hyper-V vm for your emulator (while the VM is off).
Expand the Processor node on the left and click on "Compatibility".
Now put a check mark on "Migrate to a physical computer with a different processor version" on the right.
Start your emulator in the Visual Studio Emulator tool.
Now, start debug your android project in VS using the same emulator that is already running.
After a delay (there is always a delay), your app will show up on the emulator. Yey!!
Coming from Android Studio I have already pushed apps to my Android device before (drivers and developer settings all setup), and running adb devices shows my device in the list.
What am I missing in order to be able to see my device in the Start list in Visual Studio for my Xamarin project?
Right now it just shows two virtual devices. How do I get my physical device to show up and deploy my app there?
Removed Android SDK and references in environmental variables, uninstalled Xamarin and reinstalled and let the installer create and download the SDK. Lo and behold it started to work.
Not sure what weird configuration I had prior.
I'm using visual studio 2015 update 1 with windows 10 build 10586 TH1.
also I'm using Xamarin Version 4.0.1.96.
I have created a blank Xamarin.Forms app. It deploys to Windows Phone emulators without any issue. But unable to deploy to Android Emulators.
When I start android project Android Emulator launched successfully but visual studio freeze at this step.
I've tried a lot of android emulator profiles but cannot solve the problem.
This problem only exists for Emulators and project successfully deployed on physical android device.
I have the same issue with Xamarin.Android projects.
Here is all of the text in output window:
1>Starting deploy 4.5" KitKat (4.4) HDPI Phone ...
1>Starting emulator 4.5" KitKat (4.4) HDPI Phone ...
1>Validating emulator arguments...
1>Determining if emulator is already running...
1>Preparing virtual machine...
1>Launching emulator...
1>Emulator launched successfully
Thank you in advance for your help.
I was running into the same issue with the emulator starting up find but Visual Studio getting hung on the build/deploy. Finally figured it out from here.
Visual Studio gets stuck trying to deploy the app to the emulator or the emulator does not appear as a debug target in other IDEs
If the emulator is running, but it does not appear to be connected to
ADB (Android Debug Bridge) or it does not appear in Android tools that
make use of ADB (for example, Android Studio or Eclipse), you may need
to adjust where the emulator looks for ADB. The emulator uses a
registry key to identify the base location of your Android SDK, and
looks for the \platform-tools\adb.exe file under that directory. To
modify the Android SDK path used by the emulator:
Open Registry Editor by selecting Run from the Start buttons context menu, typing regedit in the dialog box, and choosing OK.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools in the folder tree on the left.
Modify the Path registry variable to match the path to your Android SDK. Restart the emulator and you should now be able to see the
emulator connected to ADB and associated Android tools.
The value in my registry was set to "C:\Program Files (x86)\Android\android_sdk" (or similar). Updating it to "C:\Users\{USERNAME}\AppData\Local\Xamarin\MonoForAndroid\AndroidSDK" solved it for me. (I haven't yet worried about how to make this work for all users.)
I had the same issue but in my case it was not the registry. After doing a release build, I deployed the app to the emulator device in release mode which pushes the app to the device and then effectively "disconnects". These leaves a version of the app on the device which seems to block further attempts at debugging.
I solved it by starting the emulator, going to "settings -> apps" and manually uninstalling my app. Then the next debug build & deploy worked again.
I had the same issue. After a long struggle i fixed it.
Sol 1 :
Check with the registry as mentioned by others.
**HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools**
Sol 2 :
In my case there is no android-SDK tool found in registry. So you have to add the registry manually here "**HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node**"
you can add it by right click on **Wow6432Node** => **New** => **key**.
Set Key name as **"Android SDK Tools"**then right click on **Android SDK Tools** =>**New** => **String Value**
Set Name as **Path** for newly added string. Then right click on **Path** => **Modify..**
Copy the Android SDK Tools path from program files and paste in Value Data.
Now the registry is created manually. You can debug the project via emulator.
Note : Don't forgot to restart the system.
Have a look here:
Xamarin Forms Android App Crashes Running Debug with VS Android Emulator
Start the Hyper-V manager
Select the emulator you are trying to use
Right-click, hit settings
Click processor
Click Compatibility
Set checkbox “Migrate to a physical computer with a different processor version”
You do not have this issue on a laptop because its processor does not provide the new features which are unsupported by the Android Emulator for Visual Studio. The described tweak is only needed on PCs with newer CPUs.
I got round this problem by starting Visual Studio as an administrator.
I too have had weirdness with the Visual Studio Emulator for Android and visual studio appearing to be stuck at the "Deploying ..." step trying to launch the app for debugging.
What I discovered is that restarting both the emulator and visual studio seems to make things better for me once it starts to do this.
Also, when debugging an app, it seems that exiting your app normally helps compared to when using the "Stop Debugging" button.
For example, I started my app twice and killed it w/ the "Stop Debugging" button, but couldn't deploy/start the app a 3rd time w/out a restart of visual studio and the emulator.
Am using VS 2015 Community edition w/ update 3.
I just had a very interesting experience,
In my case the registry path to SDK was correct,
I had unchecked the "Use Fast Deployment" (under packaging properties in android options), and
all my efforts to reboot the PC, close VS, Close Emulator start over had failed.
However I did these two:
1 - Updated all the components in android SDK manager and restarted the PC,
2 - Disabled my anti-virus! and then suddenly VS deployed the app to the emulator!! (It was stuck in the same situation where the emulator starts and nothing happens!, I did this out of despair!)
(OS: win 7, professional, VS 2017 Community edition!)
More Details
I have been trying this for three more days
For my special case disabling the Anti Virus seems to solve the issue every single time!
The solution for me was to Check the deploy box in the Configuration Manager
This answer came from Xamarin Forum
I create blank xamarin android project without add any code when i debug this project debugging without problem but when i run app with visual studio emulator for android emulator is running but not starting my app and deploy failed and don't show me error
why ?
please help me
I had the same issue. VS 2015 can launch the VS emulator but can't deploy the app.
I was able to solve the issue like this:
Launch the emulator (F5 in VS, then cancel the deployment using the Build/Cancel menu)
Click on the chevron icon (») in the toolbar to the right of the emulator
Select the Network tab
Locate the preferred network ip address
Back in VS, click on the Open Adb Command Prompt toolbar button
Type adb connect [the emulator ip address]
Press F5 again in VS
Looks like a VS bug to me.
I had the same issue. It turned out the root cause was that the VS Emulator couldn't find adb.exe.
When that happens it won't connect to the emulator unless you do the manual connection following the steps CSharpRocks gives. The emulator also won't be listed under "adb devices".
The fix for me was to reinstall the Android SDK, using the Windows EXE based installer (not the zip installer). The EXE installer sets the HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Android SDK Tools key, Path value, in the registry, pointing to the Android SDK root directory.
The VS Emulator uses that registry setting (or the Android Studio install registry setting) to find the SDK, assuming you didn't install the Android SDK with Visual Studio itself. With that, it should be able to find adb.exe and work.
Have a look here:
Xamarin Forms Android App Crashes Running Debug with VS Android Emulator
Start the Hyper-V manager
Select the emulator you are trying to use
Right-click, hit settings
Click processor
Click Compatibility
Set checkbox “Migrate to a physical computer with a different processor version”
I'm having a very similar issue. I have found two different kind-of-work-arounds, but have not yet figured out a full solution.
Start the emulator before trying to deploy to it
Launch the Visual Studio Emulator for Android application from the start menu.
Launch one of the available emulators via the green arrow
Attempt to again launch your application from visual studio, selecting the VS Emulator N-inch... emulator from the drop down menu
For me for some reason the app still doesn't "launch" on the emulator, although it is installed. So I have to open the application menu and select my app. Additionally it will usually crash the first several times I try to open it, but eventually displays my single default label, Welcome to Xamarin Forms!.
Run the application in Ad-Hoc mode
Before running the application, change the solution configuration (from the top toolbar next to the green "run" button) to Ad-Hoc.
The problem with both of these methods though is that I'm still not able to actually debug an application. I can run it, but my breakpoints are ignored and I think that will make finding bugs difficult once I actually start to write a real application.
I hope to update this answer once I figure out an actual solution.
I had the same problem yesterday. The problem appeared (probably) because I tried to start development after a long break. I updated VS and everything, but faced many issues.
Eventually you need to start fresh
Make sure SDK for emulator points to the right place (HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Android SDK Tools)
Run Visual Studio with Administrator privileges
Go to Hyper-V Manager and delete ALL Virtual Switches - let the system recreate them when needed. It will do it properly
Delete all existing emulators and recreate them in Visual Studio. I even found a comment to name them without spaces - not sure if it is needed, but wouldn't hurt.
Doing all this helped me. But I was on the verge of reinstalling Windows 10 clean. I think lots of things and configuration changed and are no longer compatible.
Try it enabling Hyper-V and using a Visual Studio Emulator from android; that worked for me after a lot of attempts and research
I had the same issue but in my case it was not the registry. After doing a release build, I deployed the app to the emulator device in release mode which pushes the app to the device and then effectively "disconnects". This leaves a version of the app on the device which seems to block further attempts at debugging or deploying.
I solved it by starting the emulator, going to "settings -> apps" and manually uninstalling my app. Then the next debug build & deploy worked again.
You could probably also manually start the emulator and say "wipe device" option so it starts fresh.
In VS2017, on a Windows10 machine, all I had to do to get the app to show up was turn off Mobile Data.
(swipe down or use settings, then click Mobile Data and confirm to turn it off).
After I turned it back on, I could access the app. Before doing this, it always seemed that the emulator ran, but wouldn't run the app.
... no idea why this worked, but I'm posting it here in case it helps someone.
During my troubleshooting process, I also looked at these articles:
VS Android Emulator wont run application
Troubleshooting the Visual Studio Emulator for Android
Update Your Path For The New Android Emulator Location
Install apache in VS 2015 here.
Visual studio requires apache to develop android apps.
You also may want to look at some other suggestions:
notshowing, troubleshooting
I had such issues before with the android SDK emulator, now I'm using Genymotion emulator instead of it, it is more light and faster and will be detected automatically by you VS once launched.
you can download the free version from here : https://www.genymotion.com/
and also you can download any device emulator.
I recently got into Xamarin development. I have a lot of experience in Xcode making iOS apps and the iOS side was very straight forward. Now I'm trying to implement Android. I downloaded a Hello World example to get my bearings. When I run it I have no problems getting the simulator to show up (MonoForAndroid_API_10 and MonoForAndroid_API_12) but the actual application doesn't run, and does not show up anywhere on the simulator. Essentially whenever I use run or run with in Xamarin on Android, it pulls up a fully functioning, albeit empty simulator.
How do I get my application to run on the emulator?
Like the other commenters, this is most likely just a symptom of slow emulator on your machine. I'm running Xamarin-Android development on my 2010-era OSX machine in mavericks with 8GB RAM, and it is slow-slow-slow, but usable. Try to find the Intel x86 speeds improvements (look for HAXM) and you will find that the emulator will be much much faster.
And yeah, get a real handset and plug it in to your computer: always much faster than emulation.
later edit Get Genymotion for Mac OSX or for PC/Windows or PC/Linux. It's way way way faster than the other emulators. I have since found that this is as fast, or faster, than running the App on my connected Android phone. It's certainly simpler in not having to have the device plugged into one of my USB ports, and allows me to code and test on the train. http://www.genymotion.com/
Don't know if my issue was the same but finally this troubleshooting helped me to run emulator https://msdn.microsoft.com/en-us/library/mt228282.aspx#ADB.
I was missing key Android SDK Tools with string value Path in registry Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node
I've created it manually and it worked.
UPDATE
Before I got the issue with running emulator, I couldn't see it in Visual Studio. The reason was I've installed VS Android Emulator through standalone installation, not through VS Installer. It had to be installed there as well.
I had the similar issue, and then I deleted the existing device simulator and reinstalled again and it started working.
As I use a different SDK, in my case
Go to Tools > Options > Xamarin and set the Android SDK path.
Sometime Visual Studio changes this configuration;
2020 Update:
I followed the most voted comment, however, with Visual Studio 2019 updated recently, the steps have changed a little. Here is what previously worked:
WHAT WORKED BEFORE
"Don't know if my issue was the same but finally this troubleshooting helped me to run emulator https://msdn.microsoft.com/en-us/library/mt228282.aspx#ADB. I was missing key Android SDK Tools with string value Path in registry Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node
I've created it manually and it worked."
WHAT TO DO INSTEAD
Nothing. Don't mess with the path.
WHAT WORKED BEFORE
"Before I got the issue with running emulator, I couldn't see it in Visual Studio. The reason was I've installed VS Android Emulator through standalone installation, not through VS Installer. It had to be installed there as well."
Previous instructions image
WHAT TO DO INSTEAD
a. Go to Tools located at the top of the VS window, Get Tools and Features, go to Individual components, using the search tool in the pop up box, search "emulator", once you get the result, make sure both Google Android Emulator (API Level 25)(local install) and Intel Hardware Accelerated Execution Manager (HAXM) (local install) are both checked.
b. Close the solution(s) and restart VS then reopen the solution(s).
c. To deploy the app on the emulator, click Start button to spin up the emulator, left click on your Android project, then click Deploy. You should be able to see your app on your emulator's app menu.
Updated Instructions image
Worked for ME
Sometimes you close the android Emulator but not POWEROFF the Emulator.
this problem happens when emulator shutdown un-properly.
Restart Your EMULATOR
First start your emulator
Then restart your emulator by pressing down the power button and select restart option in your android emulator.
I enabled Hyper-V acceleration based on microsoft documentations: https://learn.microsoft.com/en-us/xamarin/android/get-started/installation/android-emulator/hardware-acceleration?tabs=vswin&pivots=windows#accelerating-with-hyper-v
Basically you need to turn on these two windows features from the control panel (Turn windows features on of off):
Hyper-V.
Windows hypervisor platform.
then from visual studio go to: Tools >> Android >> Android SDK manager >> Tools >> make sure that "Android emulator" version is 27.0.1 or higher, if not, you will find in the same screen a button below to update it.
I did this on windows 10 64-bit, with VS 2017 Community 15.9.5