You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Mono.Android] Use PublicApiAnalyzers to ensure we do not break API. (#8171)
Fixes: #7421
Context: #1118
Context: 07e7477
We currently have our internal `<CheckApiCompatibility/>` task
(07e7477), which ensures that we do not break backwards compatibility
between Android API levels.
Now that we are in the .NET `TargetFramework` world we also need
to ensure we do not *add* any new API to a Target Framework once it
has shipped. A `TargetFramework` is essentially a contract that we
cannot change. (Imagine if you had different minor versions of .NET
on your local machine and CI machine, what works on one should work
on the other.)
Enable Microsoft's [PublicApiAnalyzers][0] for `Mono.Android.dll`.
([PublicApiAnalyzers documentation][1].) This ensures that we don't
add new API once we've shipped `Mono.Android.dll` for a given
.NET version.
Running the `PublicApiAnalyzer` adds about 25 seconds to a local build.
One can use our existing `$(DisableApiCompatibilityCheck)` property to
also disable them to facilitate faster local build if desired.
Additionally, disable [`RS0041`][2] ("Public members should not use
oblivious types"). We should look at getting
`Android.Runtime.JniEnv.g.cs` properly annotated with nullable
reference types, and then we could enable this analyzer.
***Note***: PublicApiAnalyzers cannot be the *only* mechanism that is
used to track API compatibility for `Mono.Android.dll`, because some
binding constructs can result in compatible APIs while breaking
*semantics*. See also Issue #1118. We thus need to continue using
`<CheckApiCompatibility/>` (or some equivalent) to ensure that our
`[Register]` attribute values do not change without review.
[0]: https://github.com/dotnet/roslyn-analyzers/tree/40a3ec17a7507b8767b4ac806f29b6df179cf627/src/PublicApiAnalyzers
[1]: https://github.com/dotnet/roslyn-analyzers/blob/40a3ec17a7507b8767b4ac806f29b6df179cf627/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md
[2]: https://github.com/dotnet/roslyn-analyzers/blob/40a3ec17a7507b8767b4ac806f29b6df179cf627/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md#rs0041-public-members-should-not-use-oblivious-types
[assembly: SuppressMessage ("ApiDesign", "RS0016:Add public types and members to the declared API", Justification = "Analyzer fails due to extended characters.", Scope = "member", Target = "~F:Android.Util.Patterns.GoodIriChar")]
0 commit comments