How to fix Xamarin Android: Mono Shared MonoRuntime is not supported - xamarin

When I deploy (or archive) my Xamarin.Android application and attempt to use the .APK file in a UI test I am met with this error. My configuration is exactly how it should be for a release build.
(PLEASE READ TO THE END)
System.Exception : Mono Shared Runtime is not supported. This can be resolved by changing the project configuration or using a Release build.
Stack Trace
ApkFile.EnsureNoSharedRuntime()
AndroidAppInitializer.PrepareApkFiles(IAndroidAppConfiguration appConfiguration, ArtifactFolder artifactFolder)
AndroidApp.ctor(IAndroidAppConfiguration appConfiguration, IExecutor executor)
AndroidAppConfigurator.StartApp(AppDataMode appDataMode)
AppInitializer.StartApp(Platform platform)
Tests.BeforeEachTest()
AndroidManifest.xml
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<AndroidSupportedAbis />
</PropertyGroup>
This is ridiculous I have seen questions about this going up to FIVE years back and many unanswered. If someone knows a fix to this please let's help me and everyone else having this issue.
I literally created a brand new project with VS2022 and even on the release config. this error still shows on both emulated and physical devices.
Update: When the project is built and signed with Azure Devops the .APK file works on UITest. I am convinced this is a Visual Studio APK deployment problem.

We've had similar problems before, you can try the following methods:
1.in release mode,please make sure you uncheck use Fast Deployment(debug mode only);
2.make sure update your nuget to the latest one,the old Nuget had this issue;
3.If the problem persists,you can try the following workaround: set
<AndroidUseAssemblyStore>false</AndroidUseAssemblyStore>
in the configuration you are using with Xamarin.UITest.
4.try to delete obj and bin folders in your app and try again.

Related

How to fix Mono Shared Runtime is not supported when running UI Test

This is a very frustrating issue and I have found lots of unhelpful articles, especially since they all point to Visual Studio 2019.
I get this issue when trying to run a Xamarin.UITest project.
System.Exception : Mono Shared Runtime is not supported. This can be resolved by changing the project configuration or using a Release build.
CSPROJ FILE
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
<DebugSymbols>false</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Test</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
</PropertyGroup>
Properties
OP (Original Poster aka question-asker) seems to be doing everything right, in specifying the apk.
It appears that a SharedMonoFramework was still on the device, associated with the project's bundle id, from an earlier debug test run.
The app needed to be completely removed from the device.
One of these approaches:
Manually delete app from device.
Command prompt adb uninstall com.yourcompany.yourapp (the bundle id).
Factory reset the device.

The OutputPath property is not set for project ... / VS arbirtrarily changing configuration of projects in solution from Debug to Release

Last last week I started having an issue with every solution I've tried to build with Visual Studio. I was using VS 2019 and our organization had just pushed down some windows updates (not sure if that's related) but after the updates I was on VS 2019 version 16.8.4, .Net version 4.8.03752.
Whenever I try to build one of our solutions (I tried 3 different solutions after doing a free pull from the main branch of our repo) I get over 1000 errors which seem to be cascade errors from the OutputPath property not being set which seems to be related to several of the projects being arbitrarily changed from Debug to Release even though the solution is set to Debug | Any CPU.
Furthermore, if I examine the build tab on the project properties (or examine them in configuration manager) NO DEBUG CONFIGURATION IS SHOWN AS AVAILABLE. If I close Visual Studio it prompts to me save changes and if I do a comparison shows that it did indeed change the configuration of several projects form Debug to Release.
I have reproduced this on 2 separate machines, with fresh installs of Visual Studio 2019 (and 2017) and pulling fresh code from the repos. Other developers in my org an build the solutions just fine and their configurations show Debug | Any CPU across the board (i.e. I seem to be the only person in the world having this problem and I'm having it on every machine I've tried and with multiple versions of Visual Studio).
I also see errors saying that projects contains nuget references that are "missing" but if I restore nuget pacakges I get a messages saying they are all installed and there is nothing to restore. I also see the "missing" packages in the packages folder.
We use relative paths for the packages so it can't be the typical literal-path issue some people have. Besides which, my folder structure hasn't changed and we all use the same folder structure in our ord.
I am completely at a loss as to what to try next. My googlefoo has completely failed me in this regard.
I'm desperately hoping someone in the Stack Exchange world can offer a solution.
Thanks,
Greg.
Please check if your project's csproj file has missed these content:
You could directly add these at the bottom of the csproj file:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
After that, delete bin and obj folder.
Then, run update-package -reinstall under Tools-->Options-->Nuget Package Manager--> Package Manager Console to reinstall all nuget packages.

Azue Devops multitarget build order

I have complex Xamarin solution with android, ios and nestandard core project (defined via Microsoft.NET.Sdk) and few other csprojs with some logic (some are defined via Microsoft.NET.Sdk as netstandard2.0. others defined via MSBuild.Sdk.Extras for multitargeting the netstandard2.0, xamarin.ios10, monoandroid10.0 and have some platform specific code)
Local build on my macos with latest libraries is ok (both netcore 3 and 5, latest xamarin. tried on Rider and VS for mac).
ADO build succeed on windows-2019 agent using msbuild (just regular CI with codechecks etc)
ADO build on macos-10.15 agent (different jobs for ios and android packaging, using XamarinIos/XamarinAndroid tasks) fails with kind of strange behaviour:
i see a lot of namespace errors in droid/ios projects for platform-specific libraries from my solution.
i've made some investigations and found out that msbuild runs platform specific builds of csprojs first, copies the outputs, then runs the netstandard build for the same csprojs and replace files in output with netstandard versions. which, obviously, didn't have any line of platform specific code.
so, the question is wtf? how am i suppose to fix this?
what i tried:
replace Xamarin tasks with msbuild calls
change Xamarin SDK version to 16_12_3 and 16_12_0 (current is 16_12_2)
change .net version to 5 (current is 3.1.x) both ways - via global.json and installing v5 using the UseDotNet#2 task
core project was converted to multitarget
remove everything from sln and add every project from the scratch
also i thought that msbuild, maybe, trying to make a nupkg from my libraries so i tried this in build props:
<PropertyGroup>
<IsPackable>false</IsPackable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
</PropertyGroup>
also i have this
<PropertyGroup Label="Multiplatform" Condition=" '$(TargetsToBuild)' != 'All' ">
<TargetFrameworks Condition=" '$(TargetsToBuild)' == 'Android' ">monoandroid10.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(TargetsToBuild)' == 'iOS' ">xamarin.ios10</TargetFrameworks>
</PropertyGroup>
and multitarget projects has this
<PropertyGroup Label="Multiplatform">
<TargetFrameworks>netstandard2.0;xamarin.ios10;monoandroid10.0</TargetFrameworks>
</PropertyGroup>
of course i've tried to remove the tags above and build without them. no luck :(
So the answer is:
you should add csproj references to other projects in right order :/ order is matters for msbild

Visual Studio Pro "Could not find part of the path"

I am at my wits end here. I have checked out a project from our repo and I get this error when building:
System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\DEV\myproject\BIN\DEBUG'.'
This directory exists. I am running VS as an admin. I believe this folder is just recreated when I hit build. I would provide more information if I knew what information to provide.
Where does one begin to troubleshoot this?
I came across a similar problem - could not build in Release mode, and could not publish. I fixed it by closing VS, opening the csproj file in Notepad++ (text editor) and deleting the content in <OutputPath> for the Release mode.
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
**<OutputPath>V:\Programs\Billable_Hours\</OutputPath>**
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
Then I opened the project in VS and re-set the Release build output path to the bin/Release folder, and everything worked perfectly.

How to build a Xamarin.Android project without managed executables?

I'm tinkering with Xamarin.Forms on Visual Studio Community for Mac version 7.3.2
What I'm trying to accomplish is to convert all managed code to native executables using these options in MyApp.Droid.csproj:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<EmbedAssembliesIntoApk>false</EmbedAssembliesIntoApk>
<AotAssemblies>true</AotAssemblies>
<EnableLLVM>true</EnableLLVM>
</PropertyGroup>
EmbedAssembliesIntoApk does embed the assemblies into the apk so I've set it to false, because those are precisely what I want to get rid of.
I've also set AotAssemblies and EnableLLVM to true so the managed code is AOT compiled and converted to native code.
Those options build a signed apk with the lib/ folder containing the files below and no assemblies folder, which is what I want.
lib/
armeabi-v7a/
libgdbserver.so
libmono-profiler-log.so
libmonodroid.so
libmonosgen-2.0.so
The problem is that if I clear the application data on the device and try to run the app again it won't start giving me some error saying 'no assemblies found' or 'conflicts between different versions of the same assembly'
Is it possible to build and ship a Xamarin.Forms application for Android without any managed assemblies, but only native executables?
Update:
I tried Xamarin Studio and it adds the option BundleAssemblies, so the project setting are as follows but Xamarin fails build the target:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AndroidLinkMode>Full</AndroidLinkMode>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<AotAssemblies>true</AotAssemblies>
<EnableLLVM>true</EnableLLVM>
<BundleAssemblies>true</BundleAssemblies>
</PropertyGroup>
With those option on Visual Studio I get this executables:
lib/
armeabi-v7a/
libmonodroid_bundle_app.so
libmonodroid.so
libmonosgen-2.0.so
plus a bunch of files something.dll.so

Resources