From ae56b4a4baae92ed1bc90e7746b87439ce94a3d4 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 15 Aug 2022 14:24:49 -0400 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Use marshal-ilgen component Fixes: https://github.com/xamarin/xamarin-android/issues/7249 Context: https://github.com/dotnet/runtime/pull/71203 Context: https://github.com/dotnet/runtime/issues/60639 Context: https://github.com/dotnet/runtime/issues/61685 Mono introduced a new `marshal-ilgen` component in dotnet/runtime@de32c446 which needs to be used when *non-blittable type* is required. `string` marshaling is a form of non-blittable marshaling. Eventually the idea is that assemblies should migrate to use the [`DllImport Generator`][0] for non-blittable marshaling purposes, then [`[assembly:DisableRuntimeMarshallingAttribute]`][1] can be applied to the assembly, and -- if no assemblies in an Android app require non-blittable marshaling -- then the `marshal-ilgen` component can be omitted from the `.apk`, reducing app size. That's a fair number of `if`s; this won't be happening soon. In the meantime, we need to start including the `marshal-ilgen` component in all .NET 7 RC1+ builds so that our existing `DllImport` declarations continue to work. Update `@(_MonoComponent)` to add `marshal-ilgen`. In order to facilitate future testing, allow the `marshal-ilgen` component to be *excluded* if the `$(_AndroidExcludeMarshalIlgenComponent)` property is True. [0]: https://github.com/dotnet/runtimelab/tree/feature/DllImportGenerator [1]: https://github.com/dotnet/runtime/issues/60639 --- .../targets/Microsoft.Android.Sdk.AssemblyResolution.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets index 6318cd5f48f..188ddf12e42 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets @@ -198,6 +198,7 @@ _ResolveAssemblies MSBuild target. <_MonoComponent Condition=" '$(AndroidEnableProfiler)' == 'true' " Include="diagnostics_tracing" /> <_MonoComponent Condition=" '$(AndroidUseInterpreter)' == 'true' " Include="hot_reload" /> <_MonoComponent Condition=" '$(AndroidIncludeDebugSymbols)' == 'true' " Include="debugger" /> + <_MonoComponent Condition=" '$(_AndroidExcludeMarshalIlgenComponent)' != 'true' " Include="marshal-ilgen" />