32
votes

I'm building the sample intro xamarin forms app With Visual studio 2019 and the emulator boots up but the app doesn't deploy with the error Unexpected install output: cmd: Can't find service: package":

1>No way to resolve conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e". Choosing "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" arbitrarily.
1>C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.9\bin\keytool.exe -list -alias androiddebugkey -storepass android -keypass android -keystore "C:\Users\sticker592\AppData\Local\Xamarin\Mono for Android\debug.keystore" 
1>C:\Program Files (x86)\Android\android-sdk\build-tools\25.0.3\zipalign.exe -p 4 "C:\Users\sticker592\Downloads\FirstApp\AwesomeApp\AwesomeApp.Android\obj\Debug\81\android\bin\com.companyname.AwesomeApp.apk" "bin\Debug\\com.companyname.AwesomeApp-Signed.apk" 
1>C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.9\bin\java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\25.0.3\lib\apksigner.jar" sign --ks "C:\Users\sticker592\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 21 --max-sdk-version 27  C:\Users\sticker592\Downloads\FirstApp\AwesomeApp\AwesomeApp.Android\bin\Debug\com.companyname.AwesomeApp-Signed.apk 
1>ADB0000:  Deployment failed
1>Mono.AndroidTools.InstallFailedException: Unexpected install output: cmd: Can't find service: package
1>
1>   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in E:\A\_work\413\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:line 345
1>   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass95_0.<InstallPackage>b__0(Task`1 t) in E:\A\_work\413\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:line 753
1>   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
1>   at System.Threading.Tasks.Task.Execute()
1>ADB0010: Unexpected install output: cmd: Can't find service: package
1>
1>   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in E:\A\_work\413\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:line 345
1>   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass95_0.<InstallPackage>b__0(Task`1 t) in E:\A\_work\413\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:line 753
1>   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
1>   at System.Threading.Tasks.Task.Execute()
1>Done building project "AwesomeApp.Android.csproj" -- FAILED.
1>Build FAILED.
5
Did you try to clean/build your app and/or delete manually obj and bin is your android project ? - OrcusZ
@OrcusZ, yes indeed. I cleaned, rebuilt, and cloned the working solution all with the same. - user5389726598465
@OrcusZ I think I know what it is. The target is netstandard2.0 but I have .net 3.0 and 2.2 runtime installed for .Net development. Do I need to install the .NET 2.0 runtime for xamarin to target the 2.0 standard?? - user5389726598465
Could be, If you look the error is a mitmatch between mscorlib version. Have a look to this xamarin post : forums.xamarin.com/discussion/101704/… - OrcusZ
I have the problem on a real device. Any suggestions. - BrilBroeder

5 Answers

42
votes

In my case it helped to do a Factory Reset of the emulation device in the Android Device Manager.enter image description here

15
votes

SOLUTION FOR MANY ISSUES THAT I'VE FACED:

As user5389726598465 mentioned, "Switching from Android 9.0 Emulator to Android 8 Oreo image" makes Visual Studio to uninstall a Mono shared runtime and install a new one. It's like a Mono repair it seems.

Here are the steps within Visual Studio:

1- Create a project/solution.

2- Go to Tools > Android > Android SDK Manager.

3- Install your desired Android with all its components. e.g. Android 8 Oreo. (wait for the installation to finish!)

NOTE: If you're using Visual Studio 2019 like me you have to go with Android 8.1 Oreo or higher.

Now you can uninstall the old one - optional.

4- Go to Tools > Android > Android Device Manager.

5- Create a new device/Emulator with exactly the same OS and API version which you chose in step 1. (Do NOT go with x86_64 Processor to avoid random errors)

6- Under Solution right-click on myApp.Android project > Properties > Application > set Compile using Android version: (Target Framework) TO select your matching Android version .

7- Android device manager > Run. (Wait for Android Emulator to completely boot up.)

8- Clean then Build your solution.

9- Run the solution and wait. (This step might take more than 20 minutes for the first time with no visualizing process. Leave the computer, be patient and don't break the program until you see your output on the Emulator screen!)

Well done!

6
votes

As a workaround, switching from an Android 9.0 Emulator to Android 8 Oreo image solved the problem.

2
votes

Last week I used My Device (red box in screenshot) without issue. This week I was getting:

Mono.AndroidTools.InstallFailedException: Unexpected install output: cmd: Can't find service: package

Tweaking Reza's answer I created a new emulator in the same project, My Device 2 (purple box in screenshot), and it works on that device.

android device manager screenshot

1
votes

Just factory reset the device and let it build over. That should do the trick