Skip to content

Address build log warnings - #11625

Closed
simonrozsival wants to merge 6 commits into
mainfrom
dev/simonrozsival/build-log-warning-cleanup
Closed

Address build log warnings#11625
simonrozsival wants to merge 6 commits into
mainfrom
dev/simonrozsival/build-log-warning-cleanup

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

This separates warning cleanups from the Java.Interop work branch so they can be reviewed independently.\n\nThe changes address warnings surfaced in local build logs across runtime, installer, and test infrastructure code.

Copilot AI review requested due to automatic review settings June 10, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce local build-log warnings by cleaning up XML documentation issues, removing unused usings, and adding targeted warning suppressions across installer, runtime, and test infrastructure code.

Changes:

  • Suppress or resolve documentation-related warnings (e.g., CS1591) and improve XML doc completeness/accuracy.
  • Add targeted analyzer suppressions / nullability tweaks in runtime + test utilities.
  • Remove unused usings / tighten some nullable flows.
Show a summary per file
File Description
src/Xamarin.Installer.Common/Xamarin.Installer.Common.csproj Adds CS1591 suppression to reduce doc-warning noise.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Repository.cs Removes incorrect/obsolete XML doc parameter tag.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/JavaDependencyInstaller.cs Adjusts temp-file creation to address compiler warning.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/IProgressMonitor.cs Completes XML docs for progress-reporting parameters.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/DirectorySizeMonitoringTimer.cs Fixes XML doc parameter name/description.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/HttpClientProvider.cs Adds missing XML docs for optional parameters.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/Archive.cs Adjusts XML documentation text to avoid doc warnings.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/AndroidLicensesStorage.cs Adds missing XML doc for a boolean parameter.
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/AndroidSDKInstaller.cs Fixes/extends XML docs (param tags, formatting).
src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK.csproj Adds CS1591 suppression to reduce doc-warning noise.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.cs Adds nullability annotation to help static analysis.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs Suppresses CA1416 around Windows registry usage in tests.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/InlineData.cs Removes unused using.
src/Mono.Android/Mono.Android.csproj Removes a compile item from Mono.Android build inputs.
src/Mono.Android/Java.Interop/TypeManager.cs Tightens nullable flow around typemap resolution.
src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs Updates P/Invoke signature nullability for typemap lookup.
src/Mono.Android/Android.Runtime/JNIEnv.cs Qualifies RuntimeFeature usage and adjusts nullable return types.
src/Mono.Android/Android.Runtime/AndroidRuntime.cs Removes unused usings; qualifies RuntimeHelpers usage.
build-tools/jnienv-gen/Generator.cs Suppresses an “unassigned field” warning in generator model types.

Copilot's findings

  • Files reviewed: 19/19 changed files
  • Comments generated: 4

Comment on lines +267 to 271
static Type? GetJavaToManagedTypeCore (string? class_name)
{
if (TypeManagerMapDictionaries.JniToManaged.TryGetValue (class_name, out Type? type)) {
if (class_name is not null && TypeManagerMapDictionaries.JniToManaged.TryGetValue (class_name, out Type? type)) {
return type;
}
Comment on lines 366 to 370
<Compile Include="Microsoft.Android.Runtime\ManagedTypeManager.cs" />
<Compile Include="Microsoft.Android.Runtime\ManagedTypeMapping.cs" />
<Compile Include="Microsoft.Android.Runtime\JavaMarshalValueManager.cs" />
<Compile Include="Microsoft.Android.Runtime\RuntimeFeature.cs" />
<Compile Include="Microsoft.Android.Runtime\SimpleValueManager.cs" />
<Compile Include="Microsoft.Android.Runtime\SingleUniverseTypeMap.cs" />

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot we need to figure out how to remove it AND make sure it's accessible everywhere where it's needed (via InternalsVisibleTo I imagine). This way we don't have the same class in both Mono.Android and Mono.Android.Runtime. Only the Mono.Android.Runtime should be used everywhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done in the latest commit. RuntimeFeature.cs is now removed from Mono.Android.csprojMono.Android.Runtime already had [assembly: InternalsVisibleTo("Mono.Android, ...")] in its AssemblyInfo.cs.in, so AndroidRuntimeFeature (internal) remains accessible from Mono.Android via that existing declaration.

Comment thread build-tools/jnienv-gen/Generator.cs Outdated
@simonrozsival

Copy link
Copy Markdown
Member Author

@copilot address code review

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@copilot address code review

Addressed all four review points in commit 9cffd94:

  1. TypeManager.cs – Replaced the combined null-and-dict check with an early return null guard when class_name is null, so neither the native typemap APIs nor the dictionary Add can ever see a null key.

  2. Mono.Android.csproj – Restored RuntimeFeature.cs to the compile items. The type is internal and the copy in Mono.Android.Runtime is not accessible from Mono.Android, so it needs to be compiled into both assemblies.

  3. JavaDependencyInstaller.cs – Replaced the empty using (...); statement + CS0642 pragma with using var _ = File.Create(...).

  4. Generator.cs – Replaced the CS0649 pragma with an explicit = false field initializer.

@simonrozsival

Copy link
Copy Markdown
Member Author

@copilot let's rename RuntimeFeature class to AndroidRuntimeFeature to avoid the conflicts

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@copilot let's rename RuntimeFeature class to AndroidRuntimeFeature to avoid the conflicts

Done in commit 9b3e06d. Renamed RuntimeFeatureAndroidRuntimeFeature across all 9 affected files. JNIEnvInit.cs retains the local alias (using RuntimeFeature = Microsoft.Android.Runtime.AndroidRuntimeFeature) so its call sites didn't need individual updates. The FeatureSwitchPrefix string ("Microsoft.Android.Runtime.RuntimeFeature.") is left unchanged since it's the public feature-switch identifier used with AppContext.TryGetSwitch.

Comment thread src/Mono.Android/Java.Interop/TypeManager.cs Outdated
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
…lsVisibleTo from Mono.Android.Runtime

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
@simonrozsival

Copy link
Copy Markdown
Member Author

@copilot address this error:



       "/Users/cloudtest/vss/_work/1/s/android/Xamarin.Android.sln" (default target) (1:2) ->
       "/Users/cloudtest/vss/_work/1/s/android/src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj" (default target) (63:10) ->
       "/Users/cloudtest/vss/_work/1/s/android/src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj" (Build target) (63:11) ->
       (CoreCompile target) -> 
         /Users/cloudtest/vss/_work/1/s/android/src/Microsoft.Android.Runtime.NativeAOT/Java.Interop/JreRuntime.cs(80,8): error CS0122: 'RuntimeFeature' is inaccessible due to its protection level [/Users/cloudtest/vss/_work/1/s/android/src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj::TargetFramework=net11.0]

    240 Warning(s)
    1 Error(s)

…x CS0122 build error

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@copilot address this error:


...

Fixed. Microsoft.Android.Runtime.NativeAOT also needs AndroidRuntimeFeature but doesn't reference Mono.Android.Runtime. Added a <Compile Include> for RuntimeFeature.cs in Microsoft.Android.Runtime.NativeAOT.csproj, following the same pattern already used in Mono.Android.Runtime.csproj.

jonathanpeppers pushed a commit that referenced this pull request Jul 7, 2026
… conflict warnings (#11669)

### Summary

`Microsoft.Android.Runtime.RuntimeFeature` was compiled into **two** assemblies:

- `Mono.Android.Runtime.dll` (`src/Mono.Android.Runtime/Mono.Android.Runtime.csproj`)
- `Mono.Android.dll` (`src/Mono.Android/Mono.Android.csproj`)

Because `Mono.Android` references `Mono.Android.Runtime`, compiling `Mono.Android.dll` emitted duplicate-type warnings like:

```text
warning CS0436: The type 'RuntimeFeature' in
'src/Mono.Android/Microsoft.Android.Runtime/RuntimeFeature.cs' conflicts with the
imported type 'RuntimeFeature' in 'Mono.Android.Runtime'.
```

This PR makes `RuntimeFeature` live in **exactly one** assembly: `Mono.Android.Runtime.dll`.

### Changes

- **`Mono.Android.csproj`** — removes the duplicate `<Compile>` of `RuntimeFeature.cs`, so the type is no longer compiled into `Mono.Android.dll`.
- **`AndroidRuntime.cs`, `JNIEnv.cs`, `TypeManager.cs`** — adds `using RuntimeFeature = Microsoft.Android.Runtime.RuntimeFeature;` because once `RuntimeFeature` is imported instead of source-compiled into `Mono.Android`, the bare name conflicts with `System.Runtime.CompilerServices.RuntimeFeature`.
- **`Mono.Android.Runtime.csproj` / `Mono.Android.Runtime.targets`** — migrates assembly metadata from the hand-written `Properties/AssemblyInfo.cs.in` template to MSBuild `GenerateAssemblyInfo`:
  - Deletes `Properties/AssemblyInfo.cs.in` and the `_BuildAssemblyInfo_cs` target (which ran `ReplaceFileContents` on the template) from `Mono.Android.Runtime.targets`.
  - Sets `<GenerateAssemblyInfo>true</GenerateAssemblyInfo>` with `GenerateAssemblyConfigurationAttribute`, `GenerateAssemblyFileVersionAttribute`, `GenerateAssemblyVersionAttribute`, `GenerateRepositoryUrlAttribute`, and `IncludeSourceRevisionInInformationalVersion` all set to `false` so no new attributes are introduced vs. the old template.
  - Moves the attribute values to properties/items: `AssemblyTitle`, `Product`, `Company`, and the `InternalsVisibleTo` items. A new `_SetGeneratedAssemblyInfoProperties` target (before `GetAssemblyAttributes`) supplies `InformationalVersion`, `TargetPlatformIdentifier`/`TargetPlatformVersion`, and `SupportedOSPlatformVersion` from the existing `GetXAVersionInfo` version info.
  - Adds `InternalsVisibleTo` for `Microsoft.Android.Runtime.NativeAOT` and `Mono.Android.NET-Tests`, which previously reached `RuntimeFeature` through `Mono.Android.dll`.
  - Marks `Mono.Android.Runtime.dll` trimmable with `<IsTrimmable>true</IsTrimmable>`. This keeps the cross-assembly `RuntimeFeature` feature switches visible to ILLink in partial-trimmed apps.

### Why `IsTrimmable` is needed

Moving `RuntimeFeature` into `Mono.Android.Runtime.dll` makes `Mono.Android.dll` consume feature-switch properties across an assembly boundary. In partial trimming, ILLink only substitutes feature-switch getters in assemblies it processes. Without marking `Mono.Android.Runtime.dll` trimmable, some runtime-specific branches stayed live, causing the CoreCLR APK size-regression test to fail.

Marking `Mono.Android.Runtime.dll` trimmable lets ILLink fold those `RuntimeFeature` guards again.

### Relationship to #11625

This is a focused subset of #11625. It intentionally avoids the broader class rename (`RuntimeFeature` → `AndroidRuntimeFeature`) and resolves the resulting `CS0104` ambiguity with local `using` aliases instead.

### Follow-up

The `BuildHasTrimmerWarnings` diagnostic improvement was split out into #11981 so this PR remains focused on the `RuntimeFeature` single-assembly change.

### Verification

Latest PR validation: [dotnet-android #1496564](https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1496564) ✅

The produced `Mono.Android.Runtime.dll` from that build was inspected to confirm the `GenerateAssemblyInfo` migration is faithful — all attributes from the old `AssemblyInfo.cs.in` (`AssemblyTitle`, `Product`, `Company`, `AssemblyInformationalVersion`, `TargetPlatform=Android37.0`, `SupportedOSPlatform=Android24.0`, `InternalsVisibleTo` for `Mono.Android`) are present, the new `InternalsVisibleTo` (NativeAOT, NET-Tests) and `IsTrimmable` metadata are added, and no unexpected attributes (`AssemblyConfiguration`, `AssemblyFileVersion`, `AssemblyVersion`, `RepositoryUrl`) were introduced.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 17, 2026
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.

3 participants