Xamarin App - Can't deploy to Android 11 emulator - xamarin

Can't deploy to Android 11 emulator. (I can deploy to Android 10 emulator)
ADB0010: Deployment failed
Mono.AndroidTools.InstallFailedException: The package was not properly signed (NO_CERTIFICATES).
at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass97_0.<InstallPackage>b__0(Task`1 t)
at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<InstallPackage>d__116.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__110.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__108.MoveNext()
This is a debug build, so I'm not explicitly signing it.
But I notice that it's automatically being signed anyway with an androiddebugkey:
C:\Program Files\Android\Jdk\microsoft_dist_openjdk_1.8.0.25\bin\jarsigner.exe -keystore "C:\Users\$USERNAME$\AppData\Local\Xamarin\Mono for Android\debug.keystore" -storepass android -keypass android -digestalg SHA-256 -sigalg SHA256withRSA -signedjar bin\Debug\$UNSIGNEDAPKNAME$.apk $PATHTOAPK$.apk androiddebugkey
In case debug.keystore, was somehow out of date, (mine was timestamped 2018-03-26), I removed it and it got regenerated by the build. (with reasonable sized differences), But I still received the "Mono.AndroidTools.InstallFailedException: The package was not properly signed (NO_CERTIFICATES)." error.
I've tried cleaning and rebuilding.
I'm targeting Android 11.0 (API Level 30 -R)
Update:
I received a little more information when I manually attempting to installing with adb:
adb -e install $myapp$.apk
...
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Scanning Failed.: No signature found in package of version 2 or newer for package $PACKAGE$]

APK Signature Scheme v2 now required :
"Apps that target Android 11 (API level 30) that are currently only signed using APK Signature Scheme v1 must now also be signed using APK Signature Scheme v2 or higher. Users can't install or update apps that are only signed with APK Signature Scheme v1 on devices that run Android 11."
Signing with jarsigner.exe isn't good enough, when Targeting android 11. Signing with apksigner, includes the v2 scheme.
For example signing like this, using the same debug.keystore allows the apk to be installed on android 11.
Manually signing
"C:\Program Files (x86)\Android\android-sdk\build-tools\30.0.2\apksigner.bat" sign -ks "C:\Users\%USERNAME%\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass "pass:android" $APKNAME$.apk
Switching to apksigner via csproj file
The Xamarin build can be switched to apksigner, by adding <AndroidUseApkSigner>true</AndroidUseApkSigner> to the csproj file. (I haven't found a way to do this in the UI. perhaps this is an experimental feature?)
You must be using a relatively new BuildTools version to do this eg:
<AndroidSdkBuildToolsVersion>28.0.3</AndroidSdkBuildToolsVersion>
Now the build signs the apk like this:
C:\Program Files\Android\Jdk\microsoft_dist_openjdk_1.8.0.25\bin\java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.3\lib\apksigner.jar" sign --ks "C:\Users\%USERNAME%\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 22 --max-sdk-version 30 $APKNAME$

Related

System.Exception: Did not find MSBuild for runtime Mono

I'm compiling the sources in Visual Studio Community 2017 for Mac and I've got the following error:
Building: ServiceLayer.API (Debug)
Error: Build failed. See the build log for details. (ServiceLayer.API)
---------------------- Done ----------------------
Build failed.
Build: 1 error, 0 warnings
In Ide.log log file, I've the following entry:
ERROR [2017-10-08 20:20:45Z]: Inspector does not support this project type
ERROR [2017-10-08 20:20:45Z]: Build failed.
System.Exception: Did not find MSBuild for runtime Mono 4.0.2 (c99aa0c)
at MonoDevelop.Projects.MSBuild.MSBuildProjectService.GetNewestInstalledToolsVersion (MonoDevelop.Core.Assemblies.TargetRuntime runtime, System.Boolean requiresMicrosoftBuild, System.String& binDir) [0x0006e] in /Users/builder/data/lanes/5144/cab57de4/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProjectService.cs:1087
at MonoDevelop.Projects.MSBuild.MSBuildProjectService+<GetProjectBuilder>d__100.MoveNext () [0x00133] in /Users/builder/data/lanes/5144/cab57de4/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProjectService.cs:1116
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at MonoDevelop.Projects.Project+<GetProjectBuilder>d__157.MoveNext () [0x001bb] in /Users/builder/data/lanes/5144/cab57de4/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:1418
...
ERROR [2017-10-08 20:21:16Z]: An unhandled exception has occured. Terminating Visual Studio? False
Notes: In total like 381 lines on each attempt to build. 'End of stack trace' line is repeated 52 times.
This pointed me to this line in MonoDevelop (see: MSBuildProjectService.cs):
throw new Exception ("Did not find MSBuild for runtime " + runtime.Id);
I've checked and msbuild command exist in the command-line:
$ which msbuild
/Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild
$ msbuild --version
Microsoft (R) Build Engine version 15.4.0.0 (master/f296e67b Thu Sep 21 19:38:16 EDT 2017) for Mono
$ stat /Library/Frameworks/Mono.framework/Versions/Current
File: /Library/Frameworks/Mono.framework/Versions/Current -> /Library/Frameworks/Mono.framework/Versions/5.4.0
What I've tried so far:
I've tested both channels (Stable and Beta) in Visual Studio Update without success.
I've tried to Clean All and Rebuild All.
I've tried to remove the cache files in ~/Library/Caches/VisualStudio.
Reinstalling VisualStudio.
I've checked in Visual Studio, Preference..., Projects, .NET Runtimes and I've the latest Mono set as Default (to 5.4.x):
However when debugging, it's trying to open msbuild for 4.0.2 instead, e.g.:
$ sudo fs_usage -f pathname VisualStudio | grep -i msbuild
12:34:38 stat64 /Library/Frameworks/Mono.framework/Versions/4.0.2/lib/mono/msbuild>>>>>>>>>>>>>>>>>>>>>> 0.000007 VisualStudio
12:34:38 lstat64 /Library/Frameworks/Mono.framework/Versions/4.0.2/lib/mono/msbuild>>>>>>>>>>>>>>>>>>>>>> 0.000002 VisualStudio
12:34:38 access /Library/Frameworks/Mono.framework/Versions/4.0.2/lib/mono/msbuild>>>>>>>>>>>>>>>>>>>>>> 0.000002 VisualStudio
which doesn't exist.
How should I add a missing MSBuild to my Solution (project) (as per mentioned error)?
Mono 4.0.2 did not have msbuild, it was included in 4.8.0+ . Check where does /Library/Frameworks/Mono.framework/Versions/Current (symlink) point to. It probably points to some mono 5.x.y . Try changing the .NET runtime that VSMac is set to use in Preferences -> Projects -> .NET Runtimes, to the latest one.
For some reason it is still looking it in 4.0.2. I would try to, at least temporarily, remove that 4.0.2 directory and then check. But otherwise I think your installation is broken and I would try to reinstall the whole thing (VSMac, Mono, ..).
Also, check in your Ide.log file for any references to 4.0.2, before that exception.
If you run into the same issue even with a fresh install, then please file a bug at bugzilla.xamarin.com and we can try to debug it there.

Visual Studio 2017 installer keeps telling me "elevation required"?

When I try to install VS 2017 on a machine, the installer gives me the following error despite the fact that I'm already an administrator (yes I've tried "Run as Administrator" and messing with UAC etc... trust me I've tried all the usual stuff and know how Windows works):
Elevation Required
This program requires administrator privileges to perform setup operations.
Please rerun the program as administrator.
Tracing with ProcMon, I see a log in my temp directory that seems to be indicating the cause:
Information : Log configuration: $SERVICEHUBTRACELEVEL=""
Error : HubHost 'desktopClr$C94B8CFE-E3FD-4BAF-A941-2866DBB566FE' PID 3736 stderr: Error running host: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: creationOptions
at System.Threading.Tasks.Task..ctor(Object state, TaskCreationOptions creationOptions, Boolean promiseStyle)
at Microsoft.ServiceHub.HostLib.Host..ctor(String hostId, String pipeName, DevHubTraceSource logger)
at Microsoft.ServiceHub.HostLib.Program.<MainAsync>d__0.MoveNext()
Error : HubHost 'desktopClr$C94B8CFE-E3FD-4BAF-A941-2866DBB566FE' PID 3736 stderr:
Error : HubHost 'desktopClr$C94B8CFE-E3FD-4BAF-A941-2866DBB566FE' PID 3736 stderr: Unhandled Exception:
Error : HubHost 'desktopClr$C94B8CFE-E3FD-4BAF-A941-2866DBB566FE' PID 3736 stderr: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: creationOptions
at System.Threading.Tasks.Task..ctor(Object state, TaskCreationOptions creationOptions, Boolean promiseStyle)
at Microsoft.ServiceHub.HostLib.Host..ctor(String hostId, String pipeName, DevHubTraceSource logger)
at Microsoft.ServiceHub.HostLib.Program.<MainAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceHub.Host.Program.Main(String[] args)
Error : Error starting service 'SetupEngine.ProductsProvider' requested by ProductsProvider (pid: 3340): Hub host 'desktopClr', PID: 3736 exited. code: '3762504530'.
Error : Error starting service 'SetupEngine.Installer' requested by Installer (pid: 3340): Hub host 'desktopClr', PID: 3736 exited. code: '3762504530'.
It seems their code is buggy except this is only happening on my machine? Why isn't everyone seeing this? What's triggering this problem and how do I fix it?
I finally solved this by installing .NET Framework 4.7, though I suspect updating 4.0 to even a slightly more recent version might work too.
The issue seemed to be a bug in the System.Threading.Tasks.Task class, where it didn't allow passing a flag that was supposed to be legal. I assumed this was a version mismatch and fixed.
I downloaded VS preview https://visualstudio.microsoft.com/vs/preview/ then it worked fine again
In my case, the cause was the TMP and TEMP environment variables, pointing to non-available paths, on removed drives.

Visual studio extension error?

My newly installed Visual studio poped up a dialog box with the message of
An exception has been encountered. This may be caused by an extension.
You can get more information by examining the file 'C:\Users....\AppData\Roaming\Microsoft\VisualStudio\14.0\ActivityLog.xml'.
And I found the following errors in the xml file.
A MEF Component threw an exception at runtime: Microsoft.VisualStudio.Composition.CompositionFailedException: An exception was thrown while initializing part "Microsoft.VisualStudio.IntelliTrace.SourceControl.HistoricalModeHint.HistoricalModeTaggerProvider". ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Diagnostics.Utilities, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. at Microsoft.VisualStudio.IntelliTrace.SourceControl.HistoricalModeHint.HistoricalModeTaggerProvider..ctor(SVsServiceProvider serviceProvider, IVsEditorAdaptersFactoryService adapterFactory) --- End of inner exception stack trace --- at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.b__0()
and
Microsoft.VisualStudio.Composition.CompositionFailedException: An exception was thrown while initializing part "Microsoft.VisualStudio.IntelliTrace.SourceControl.HistoricalModeHint.HistoricalModeTaggerProvider". ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Diagnostics.Utilities, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. at Microsoft.VisualStudio.IntelliTrace.SourceControl.HistoricalModeHint.HistoricalModeTaggerProvider..ctor(SVsServiceProvider serviceProvider, IVsEditorAdaptersFactoryService adapterFactory) --- End of inner exception stack trace --- at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.b__0() --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.b__0() at Microsoft.VisualStudio.Composition.DelegateServices.<>c__DisplayClass2_01.<As>b__0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.GatherTaggers(ITextBuffer textBuffer)
I tried to repair VS but it doesn't help. I also tried to force the cache to be rebuilt:
Delete the contents of the folder at "%LOCALAPPDATA%\Microsoft\VisualStudio\14.0\ComponentModelCache"
Run "DevEnv.exe /setup" (this is under "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE", but should be on your PATH if you open a Developer Command Prompt).
Try to run the VS with safe mode using the command: devenv /safemode, if it works fine, that means the installed extensions caused this issue, you can go to Tools—Extensions and Updates and click ‘Updates’ tab and install all updates, then reopen VS. Or click ‘Installed’ tab and remove/uninstall the installed extensions one by one to find the culprit.
Another thing you can try is to run visual studio as administrator, it can help us to excludes the permission issue.

Deployment failed because of an internal error: An item with the same key has already been added

I'm using VS2013, Xamarin.Android 4.12.4.20.
Build is successful.
I'm getting error from title whenever I try to deploy in debug mode or package.
It started to happened today it work fine before.
I've restarted VS, device, PC - none helped.
Stack trace:
Xamarin.AndroidTools.AndroidDeploymentException: InternalError ---> System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Mono.AndroidTools.Adb.AdbSyncDirectory.Add(AdbSyncItem entry)
at Xamarin.AndroidTools.AndroidDeploySession.InstallAssemblies(String destinationPath, CancellationToken token)
at Xamarin.AndroidTools.AndroidDeploySession.FastDev()
at Xamarin.AndroidTools.AndroidDeploySession.Run(CancellationToken token)
at Xamarin.AndroidTools.AndroidDeploySession.RunLogged(CancellationToken token)
--- End of inner exception stack trace ---
at Xamarin.AndroidTools.AndroidDeploySession.RunLogged(CancellationToken token)
at Xamarin.AndroidTools.AndroidDeploySession.Start(CancellationToken token)
Build output:
3>Build succeeded.
3>Waiting for device..
3>Detecting installed packages
3>Detecting installed packages...
3>
3>Removing previous version of application
3>Removing previous version of application...
3>
3>Installing application on device
3>Copying application to device...
3>
3>Getting installation path...
I've figured it out. Make sure that you don't have different versions of the same dll referenced!!
Let me describe my set up a bit more that will help with explaining why exception happened.
I've got two projects
Domain - library with code shared between all platforms
Android - android specific code
Both have nuget references to the same library. At some point android (only in this project) nuget references have been updated which resulted in two versions of the same library required by the application (Domain project still referenced old nuget).
When I tried to package solution I would get warning like :
Consider app.config remapping of assembly "{Library}" from Version "5.6.0.0" [] to Version "5.6.1.0" [{Path}] to solve conflict and get rid of warning.
Once I've update Domain's nuget everything worked.

mdtool Did not find registered GTK# installation

I'm new to Xamarin Studio and mdtool so apologies for the noob question but I'm completely stuck on this and my Google searches aren't finding the answer to my problem.
Basically our solution builds perfectly in Xamarin Studio and now I need to run it from the command line so I can put it into our standard buildsystem but I appear to have missed something in the setup or configuration as it complains about the fact that it cannot find a registered GTK# installation.
I have installed Mono for windows 2.10.9 which contains GTK# 2.12.11 but I have also installed the standalone GTK# 2.12.20 because our developer says he has that installed and it is all installed on Windows Server 2012 in a VM at the moment while I test it all.
Here is the command I'm running to get it built and the eror that it responds with:
mdtool build '--configuration:Release' test_mono.sln
ERROR [2013-05-24 15:56:25Z]: Did not find registered GTK# installation
MonoDevelop Build Tool
System.TypeInitializationException: The type initializer for 'Mono.Unix.Native.Stdlib' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect
format. (Exception from HRESULT: 0x8007000B)
at Mono.Unix.Native.Stdlib.GetDefaultSignal()
at Mono.Unix.Native.Stdlib..cctor()
--- End of inner exception stack trace ---
at Mono.Unix.Native.Stdlib.free(IntPtr ptr)
at Mono.Unix.Catalog.MarshalStrings(String s1, IntPtr& p1, String s2, IntPtr& p2, String s3, IntPtr& p3)
at Mono.Unix.Catalog.Init(String package, String localedir)
at MonoDevelop.Core.GettextCatalog..cctor()
The type initializer for 'Mono.Unix.Native.Stdlib' threw an exception.
Any ideas what I've done wrong or overlooked?

Resources