Skip to content

Known issues in .NET

Jonathan Peppers edited this page Oct 27, 2022 · 22 revisions

Release builds using LLVM in .NET 7

In some cases, LLVM apps crash on startup with:

10-18 23:55:17.844 20389 20389 D monodroid-assembly: monodroid_dlopen: hash match found, DSO name is 'libaot-Mono.Android.dll.so'
10-18 23:55:17.844 20389 20389 I monodroid-assembly: Trying to load shared library '/data/app/~~4kGTzxWG6HKO7nzyg6ryBg==/com.companyname.hellomaui.old-h8Jlutcvf8Dzfpuuq1ouUA==/lib/arm64/libaot-Mono.Android.dll.so'
10-18 23:55:17.844 20389 20389 I monodroid-assembly: Failed to load shared library '/data/app/~~4kGTzxWG6HKO7nzyg6ryBg==/com.companyname.hellomaui.old-h8Jlutcvf8Dzfpuuq1ouUA==/lib/arm64/libaot-Mono.Android.dll.so'. dlopen failed: cannot locate symbol "memset" referenced by "/data/app/~~4kGTzxWG6HKO7nzyg6ryBg==/com.companyname.hellomaui.old-h8Jlutcvf8Dzfpuuq1ouUA==/lib/arm64/libaot-Mono.Android.dll.so"...

It is currently required to pass an $(AndroidNdkDirectory) during your build. For example, on Azure DevOps you could use:

-p:AndroidNdkDirectory=$(ANDROID_NDK_HOME) 

See: https://github.com/xamarin/xamarin-android/pull/7475

Additionally, some apps built with -p:EnableLLVM=true can crash on startup with:

10-21 09:29:08.341 10012 10012 E AndroidRuntime: android.runtime.JavaProxyThrowable: System.PlatformNotSupportedException: Arg_PlatformNotSupported
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at System.String.MakeSeparatorListVectorized(ValueListBuilder`1& , Char , Char , Char )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at System.String.MakeSeparatorList(ReadOnlySpan`1 , ValueListBuilder`1& )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at System.String.SplitInternal(ReadOnlySpan`1 , Int32 , StringSplitOptions )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at System.String.Split(Char[] )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.Controls.BindingExpression.ParsePath()
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.Controls.BindingExpression..ctor(BindingBase binding, String path)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.Controls.Binding.set_Path(String value)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.Controls.Binding..ctor(String path, BindingMode mode, IValueConverter converter, Object converterParameter, String stringFormat, Object source)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.Controls.ShellItem.CreateFromShellSection(ShellSection shellSection)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.Controls.ShellItem.op_Implicit(ShellSection shellSection)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.Controls.ShellItem.op_Implicit(ShellContent shellContent)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at HelloMaui.AppShell.InitializeComponent()
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at HelloMaui.App..ctor()
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite , RuntimeResolverContext )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at System.Collections.Concurrent.ConcurrentDictionary`2[[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type , Func`2 )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider , Type )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IApplication](IServiceProvider )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Microsoft.Maui.MauiApplication.OnCreate()
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Android.App.Application.n_OnCreate(IntPtr , IntPtr )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at crc6488302ad6e9e4df1a.MauiApplication.n_onCreate(Native Method)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at crc6488302ad6e9e4df1a.MauiApplication.onCreate(MauiApplication.java:28)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6785)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:106)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.os.Looper.loopOnce(Looper.java:201)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:288)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7898)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
10-21 09:29:08.341 10012 10012 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

This will be addressed in a future service release for the .NET runtime.

See: https://github.com/dotnet/runtime/issues/77319

Building net6.0-android apps from .NET 7 in Release mode

.NET 7 RC 2 now supports this scenario for all builds!

Specifying both -f and -r to dotnet build fails to restore for multi-targeted projects

This will manifest as a build error like this:

error : The RuntimeIdentifier 'android-arm64' is invalid.

The cause is that by passing -r <runtime identifier> to 'dotnet build' that runtime identifier is used for all target frameworks in the project file when the project is restored, while it's only a valid runtime identifier for one of the target frameworks.

Potential workaround is to restore manually, and build without restoring:

$ dotnet restore
$ dotnet build --no-restore -f net6.0-android -r android-arm64

This happens with dotnet publish as well.

This will be fixed in a future version of NuGet.

Ref: https://github.com/dotnet/sdk/issues/21877.
Ref: https://github.com/NuGet/Home/issues/11653.

dotnet pack and .aar files

In some cases .aar files are not packaged correctly for .nupkg output of Android class libraries.

For example:

  1. dotnet new androidlib
  2. Add MyAndroidLibrary.aar file
  3. dotnet pack
  4. lib\net6.0-android31.0\MyAndroidLibrary.aar is missing from the .nupkg

To workaround this issue, add the following to your .csproj file:

<ItemGroup>
  <AndroidLibrary Update="**\*.aar" Pack="false" />
  <None Update="**\*.aar" Pack="true" PackagePath="lib\$(TargetFramework)$(TargetPlatformVersion)" />
</ItemGroup>

Ref: https://github.com/xamarin/xamarin-android/issues/7040.
Ref: https://github.com/xamarin/xamarin-android/pull/7045.

Clone this wiki locally