Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[One .NET] fix remaining Mono.Android.Export linker warning #6216

Merged

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Aug 20, 2021

Context: #5652

If you build an app with:

> dotnet build -c Release -p:SuppressTrimAnalysisWarnings=false

You get the linker warning:

src\Mono.Android\Android.Runtime\AndroidRuntime.cs(296,5): warning IL2026: Android.Runtime.AndroidTypeManager.CreateDynamicCallback(MethodInfo): Using method 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.

We can simply suppress the warning:

[UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "DynamicDependency should preserve the Create() method.")]

If we applied this, every app would preserve
Mono.Android.Export.dll, so we should not do this:

[DynamicDependency ("Create", "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

This is already preserved because we have a DynamicDependency in
ExportAttribute.cs:

[DynamicDependency (DynamicallyAccessedMemberTypes.All, "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

I also had to bring in the source for UnconditionalSuppressMessage
for monoandroid10 or netstandard2.0 assemblies. I also changed an
MSBuild Condition, so it will continue to work in .NET 7.

@jonathanpeppers jonathanpeppers changed the title [One .NET] remove in-tree DynamicDependencyAttribute [One .NET] fix remaining Mono.Android.Export linker warning Aug 27, 2021
@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 31, 2021 14:00
@@ -0,0 +1,92 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this file was copied from elsewhere -- which I think it was -- then it should instead be in e.g. src-ThirdParty/….

This was overlooked with DynamicallyAccessedMemberTypes.cs and DynamicDependencyAttribute.cs, so those should likewise move. :-(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be moved around now.

Context: dotnet#5652

If you build an app with:

    > dotnet build -c Release -p:SuppressTrimAnalysisWarnings=false

You get the linker warning:

    src\Mono.Android\Android.Runtime\AndroidRuntime.cs(296,5): warning IL2026: Android.Runtime.AndroidTypeManager.CreateDynamicCallback(MethodInfo): Using method 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.

We can simply suppress the warning:

    [UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "DynamicDependency should preserve the Create() method.")]

If we applied this, every app would preserve
`Mono.Android.Export.dll`, so we should not do this:

    [DynamicDependency ("Create", "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

This is already preserved because we have a `DynamicDependency` in
`ExportAttribute.cs`:

    [DynamicDependency (DynamicallyAccessedMemberTypes.All, "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

I also had to bring in the source for `UnconditionalSuppressMessage`
for `monoandroid10` or `netstandard2.0` assemblies. I also changed an
MSBuild `Condition`, so it will continue to work in .NET 7.
@jonpryor jonpryor merged commit 8eb10dd into dotnet:main Sep 3, 2021
@jonathanpeppers jonathanpeppers deleted the dotnet-remove-dynamicdependency branch September 3, 2021 02:07
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants