Skip to content

Builds with AOT enabled and linking disabled copy assemblies directly from packs/nugets #7389

Description

@grendello

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

.NET 7.0 preview (XA main)

Description

When application is built with

dotnet build -bl -c Release -p:RunAOTCompilation=true -p:AndroidEnableProfiledAot=true -p:PublishTrimmed=false

The assemblies used by the AOT compiler as input are copied from their original location (packs, nugets) instead of from the obj/Release/net7.0-android/assets directory. An excerpt from the msbuild log:

Copying .../perftest/obj/Release/net7.0-android/HelloAndroid.dll to obj/Release/net7.0-android/android-x86/aot-in/HelloAndroid.dll
Copying .../xamarin-android/bin/Release/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-x86/7.0.0-rc.2.22451.11/runtimes/android-x86/lib/net7.0/Microsoft.CSharp.dll to obj/Release/net7.0-android/android-x86/aot-in/Microsoft.CSharp.dll
Copying .../xamarin-android/bin/Release/lib/packs/Microsoft.Android.Runtime.33.android-x86/33.0.0/runtimes/android-x86/lib/net7.0/Mono.Android.dll to obj/Release/net7.0-android/android-x86/aot-in/Mono.Android.dll
Copying .../.nuget/packages/xamarin.androidx.activity/1.2.3/lib/monoandroid90/Xamarin.AndroidX.Activity.dll to obj/Release/net7.0-android/android-x86/aot-in/Xamarin.AndroidX.Activity.dll

This causes AOT to ignore any changes made to assemblies in obj/Release/net7.0-android/android/assets, which causes e.g. the applications using marshal methods to crash at runtime, since the assemblies rewritten to
support marshal methods aren't read by AOT but they are packaged (from obj/Release/net7.0-android/android/assets) into the apk. This causes incompatibilities between the native shared libraries generated by the
AOT compiler and the actual assemblies (as well as the Xamarin.Android runtime) included in the application:

09-16 21:35:17.706 28158 28158 E t6.helloandroid: * Assertion at /__w/1/s/src/mono/mono/metadata/class-init.c:2354, condition `klass->instance_size == instance_size' not met
--------- beginning of crash
09-16 21:35:17.706 28158 28158 F libc    : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 28158 (t6.helloandroid), pid 28158 (t6.helloandroid)

The above SIGABRT is caused by the fact that the marshal methods assembly rewriter removed some and added other methods to some assemblies, but AOT processed the original, unmodified, assemblies and thus the
class sizes differ.

Steps to Reproduce

Build application with:

dotnet build -bl -c Release -p:RunAOTCompilation=true -p:AndroidEnableProfiledAot=true -p:PublishTrimmed=false

and examine the generated msbuild.binlog to see that assemblies serving as input for the AOT compiler are not copied from the obj/Release/net7.0-android/android/assets directory but from their original locations in packs/nugets

Did you find any workaround?

Build with AOT and linking enabled.

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions