[Mono.Android] Use PublicApiAnalyzers to ensure we do not break API. #8171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #7421
Enable Microsoft's PublicApiAnalyzers for
Mono.Android.dll.We currently have
ApiCompat, which ensures that we do not break backwards compatibility between Android API levels, but now that we are in the .NETTargetFrameworkworld we also need to ensure we do not add any new API to a TF once it has shipped. ATargetFrameworkis 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.)Running the
PublicApiAnalyzeradds about 25 seconds to a local build. One can use our existing$(DisableApiCompatibilityCheck)property we have to also disable them to facilitate faster local build if desired.Additionally, disable
RS0041("Public members should not use oblivious types"). We should look at gettingAndroid.Runtime.JniEnv.g.csproperly annotated with NRT and then we could enable this analyzer.