简体   繁体   中英

Xamarin deploying not working with Android

I've set up a new Xamarin.Forms Project. I want to build and deploy it to an emulator or an Android device, but it is not working. In the Outputwindow of Visual Studio, the following error is displayed:

The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).

Update:

If I look in the build logs i can find following:

2>Mono.AndroidTools.InstallFailedException: Unexpected install output: Error: Could not access the Package Manager. Is the system running?

2> bei Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)

2> bei Mono.AndroidTools.AndroidDevice.c__AnonStoreyD.<>m__0(Task`1 t)

2> bei System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()

2> bei System.Threading.Tasks.Task.Execute()

2>Deployment failed because of an internal error: Unexpected install output: Error: Could not access the Package Manager. Is the system running?

You need to first set the Android project as the Startup Project . Right click the Android Project and select Set as StartUp project .

Ensure that you have checked the Build and Deploy checkboxes. You can right click the Solution and select Configuration Manager .


Also, please ensure that the Emulator is already running .

You need to wait for the emulator to full start - takes about a few minutes. Once it is fully started (UI on the emulator will change), it should work.

You will need to restart the app after the emulator is running and choose the running emulator (when prompted).

This can be caused by a few things. When ever I get this, I switch the Output window drop-down to Build . Usually that shows an INCOMPATIBLE error of some kind. That usually means the app install on the device/emulator got corrupted/messed up in some way. The app probably will not even show up on the app dashboard area but if you go into Settings -> App (or App Manager) -> then look for the app's App ID (NOT the app's name) . When you find it, uninstall it and try again.

Another common cause of the error for me is that the correct architecture is not selected in the Android project properties. This usually is the case when trying to run on the Xamarin Android Player. To fix that, right-click the Xamarin Android project -> Properties -> Android Options -> Advanced -> select x86

This means you are deploying to a device/emulator with an app that doesn't contain the appropriate architecture.

So let's make sure you have the following, first go to your android project options and make sure you have these checked:

在此输入图像描述

Then you might also need to click Advanced on this screen and check the appropriate architectures:

在此输入图像描述

I keep getting this error too with an Android emulator running Android 4.4.2 (though I am not using Xamarin.Forms) and it only happens with that emulator. I resolve it as follows:

1) In the command console (cmd.exe) type the following commands to restart ADB:

adb kill-server
adb start-server

2) In your project choose the Build menu and choose Clean Solution .

3) Try deploying the app again.

You might have to repeat the above twice sometimes (if it doesn't work its a good idea to shut down the emulator and then restart ADB then try deploy again).

In my case application icon needs to be set on Android Manifest.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM