Uh oh!
There was an error while loading. Please reload this page.
[Mono.Android] Fix build warnings in Mono.Android and build tooling - #11958
[Mono.Android] Fix build warnings in Mono.Android and build tooling#11958simonrozsival wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR focuses on reducing compiler/analyzer noise in the .NET for Android codebase by tightening nullability annotations, adding targeted suppressions/attributes, and cleaning up PublicAPI lists, primarily in src/Mono.Android and related build/test tooling.
Changes:
- Adjust nullability and add explicit null-handling in core interop/runtime code (
JNIEnv,TypeManager) and in generated bindings (AnimatorSet,ValueAnimator). - Add/suppress warnings where appropriate (CA1416 in test helper, CS0649 for native-populated structs, CS0436 in
Mono.Android.csproj). - Clean up API surface bookkeeping (remove duplicate
PublicAPI.Shipped.txtentries) and minor test/tooling cleanup.
Show a summary per file
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs | Suppresses CA1416 around Windows-only registry access in test tooling |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/InlineData.cs | Removes a duplicate using |
| src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs | Updates helper signature to accept nullable message |
| src/Mono.Android/PublicAPI/API-37/PublicAPI.Shipped.txt | Removes a duplicate shipped API entry |
| src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Shipped.txt | Removes a duplicate shipped API entry |
| src/Mono.Android/Mono.Android.csproj | Adds CS0436 to NoWarn |
| src/Mono.Android/Microsoft.Android.Runtime/JniRemappingLookup.cs | Suppresses CS0649 for a native-populated struct |
| src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalRegisteredPeers.cs | Suppresses CS0649 for an internal native-mirrored struct |
| src/Mono.Android/Java.Interop/TypeManager.cs | Adds null checks for strings coming from native pointers / mapping lookups |
| src/Mono.Android/Android.Runtime/JNIEnv.cs | Enables nullable context and tightens null-handling for typemap/array helpers |
| src/Mono.Android/Android.Bluetooth/BluetoothDevice.cs | Adds ObsoletedOSPlatform("android37.0") to obsolete overloads |
| src/Mono.Android/Android.Animation/ValueAnimator.cs | Addresses nullable warnings in generated binding code |
| src/Mono.Android/Android.Animation/AnimatorSet.cs | Addresses nullable warnings in generated binding code |
| build-tools/jnienv-gen/Generator.cs | Suppresses CS0649 for generator metadata populated indirectly |
Copilot's findings
- Files reviewed: 14/14 changed files
- Comments generated: 4
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jonathanpeppers
commented
Jul 2, 2026
/review |
✅ Android PR Reviewer completed successfully! |
There was a problem hiding this comment.
🤖 Code review
Focused, well-scoped warning cleanup. Nice touches: the pragma suppressions carry explanatory comments, the CS0649 suppressions on native-mirror structs are appropriate, the new argument checks use nameof, and the duplicate using System.Globalization; removal in InlineData.cs is genuine dead-code removal. I read the full source around each change; everything below is non-blocking and surfaced inline.
- Incomplete PublicAPI dedup — the cleanup removed the
VP9Profile2HDRduplicate but an exact-duplicateVP9Profile3HDRline remains right below it in bothAPI-36.1andAPI-37/PublicAPI.Shipped.txt(lines 66145/66146), leaving the sameRS0025duplicate-entry warning this PR is clearing. Details inline.
💡 Suggestions (3)
#nullable enableinJNIEnv.csis redundant — nullable is already enabled project-wide (Mono.Android.csproj:24).string? type = GetClassNameFromInstance (array)inJNIEnv.cs, plus itstype == nullcheck, are now dead since the same PR made that method return non-nullstring.AnimatorSet.cs/ValueAnimator.csuse?? throwfor the object return but keep!on__this; the generated-mirror pattern in sibling files uses!for that return.
Accuracy note: a few changes do subtly alter behavior on previously null/NRE paths — GetClassNameFromInstance, AnimatorSet/ValueAnimator.SetDuration, and the managed→java typemap now throw a clear exception where they would previously have returned null. That is an improvement, just not strictly “no behavioral change.”
CI: no checks had reported at review time (status still pending), so a green build is unconfirmed; mergeable_state was blocked.
Verdict:
Generated by Android PR Reviewer for #11958 · 417.8 AIC · ⌖ 23.6 AIC · ⊞ 6.8K
Comment /review to run again
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Addresses several compiler/analyzer warnings, primarily in Mono.Android.csproj: - Add nullable annotations and null checks in JNIEnv, TypeManager, and generated bindings (AnimatorSet, ValueAnimator) to resolve CS86xx nullability warnings. - Annotate obsoleted BluetoothDevice.ConnectGatt overloads with ObsoletedOSPlatform. - Suppress CS0649 on internal control-block/replacement-method structs that are populated from native code (JavaMarshalRegisteredPeers, JniRemappingLookup, jnienv-gen). - Suppress CA1416 for the Windows-only registry access in AndroidSdkResolver. - Allow CS0436 in Mono.Android.csproj NoWarn. - Remove duplicate PublicAPI.Shipped.txt entries (API-36.1, API-37). - Remove duplicate using in InlineData test helper. - Widen AndroidMessageHandler.CreateHttpRequestException message parameter to nullable.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ve and pragma - Remove leftover byte-identical VP9Profile3HDR duplicate in API-36.1 and API-37 PublicAPI.Shipped.txt (clears the RS0025 the PR targets). - Drop redundant per-file '#nullable enable' in JNIEnv.cs (nullable is enabled project-wide) and remove the now-dead 'string?'/'type == null' check since GetClassNameFromInstance returns non-null. - Replace misleading CA1416 pragma with an analyzer-recognized OperatingSystem.IsWindows() guard in AndroidSdkResolver.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…line The API-37 (CinnamonBun preview) PublicAPI baseline (PublicAPI.Shipped.txt is a copy of API-36.1) is out of date with the generated android-37 bindings, so the PublicApiAnalyzer reports thousands of RS0016 (undeclared public API) and RS0017 (declared-but-missing) errors that are unrelated to this warning-cleanup PR. Suppress RS0016/RS0017 via NoWarn (which overrides the WarningsAsErrors escalation) to unblock the build. A follow-up PR will regenerate the API-37 PublicAPI.Shipped.txt / PublicAPI.Unshipped.txt files to declare the new API surface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3aaec9c to
d8745bbCompare| #pragma warning disable CS0649 // Field 'JniFunction.Prebind' is never assigned to, and will always have its default value false | ||
| // If true, then we initialize the binding on the static ctor, we dont lazy-define it | ||
| public bool Prebind; | ||
| #pragma warning restore CS0649 |
There was a problem hiding this comment.
This was removed in main, so I think we can rebase.
simonrozsival
commented
Jul 7, 2026
Superseded by #11999 |
Fixes several compiler/analyzer warnings, primarily surfaced when building
Mono.Android.csproj.Changes
JNIEnv,TypeManager, and the generatedAnimatorSet/ValueAnimatorbindings.ConnectGattoverloads with[ObsoletedOSPlatform("android37.0")].JavaMarshalRegisteredPeers,JniRemappingLookup, andjnienv-gen'sGenerator).AndroidSdkResolver.NoWarninMono.Android.csproj.PublicAPI.Shipped.txtentries (API-36.1, API-37).using System.Globalization;in theInlineDatatest helper and widenAndroidMessageHandler.CreateHttpRequestException'smessageparameter to nullable.No functional/behavioral changes — warning cleanup only.