Skip to content

[trimming] using "Layout Binding" feature has trimming warnings #8807

Closed
@jonathanpeppers

Description

@jonathanpeppers

Android application type

.NET Android (net7.0-android, net8.0-android, etc.)

Affected platform version

.NET 9

Description

Some initial fixes here: #8805

But we are still left with:

bin\Release\dotnet\packs\Microsoft.Android.Sdk.Windows\...\tools\LayoutBinding.cs(35,11): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Android.App.Activity.FindViewById<T>(Int32)'. The generic parameter 'T' of 'Xamarin.Android.Design.LayoutBinding.FindView<T>(Int32, ref T)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. 
bin\Release\dotnet\packs\Microsoft.Android.Sdk.Windows\...\tools\LayoutBinding.cs(37,11): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Android.Views.View.FindViewById<T>(Int32)'. The generic parameter 'T' of 'Xamarin.Android.Design.LayoutBinding.FindView<T>(Int32, ref T)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. 
bin\Release\dotnet\packs\Microsoft.Android.Sdk.Windows\...\tools\LayoutBinding.cs(79,56): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Android.App.FragmentManager.FindFragmentById<T>(Int32)'. The generic parameter 'T' of 'Xamarin.Android.Design.LayoutBinding.FindFragment<T>(Int32, Fragment, ref T)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. 

I don't think the trimmer can handle:

T __FindFragment<
		[DynamicallyAccessedMembers (Constructors)]
		T
> (
		int resourceId,
		Func<Activity, [DynamicallyAccessedMembers (Constructors)] T> finder,
		ref T cachedField)
	where T: Java.Lang.Object
{
	if (cachedField != null)
		return cachedField;

It doesn't like the ref T parameter.

Steps to Reproduce

Build tests\Mono.Android-Tests\Runtime-Microsoft.Android.Sdk\Mono.Android.NET-Tests.csproj in release mode with TrimMode=full

Did you find any workaround?

I suppressed the warnings in #8805 for now.

Relevant log output

No response

Metadata

Metadata

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions