Repository navigation
[AndroidSdk] Replace uname and rename P/Invokes - #13457
Conversation
* OS.IsRunningOnMac: use OperatingSystem (net) / RuntimeInformation (netstandard2.0) platform checks instead of P/Invoking uname(3). All Apple platforms are matched, as uname reports "Darwin" on each. * FileUtil.SystemRename: use a LibraryImport'd rename(2) on .NET, keeping exact rename(2) and errno semantics; netstandard2.0 keeps the DllImport. File.Move(overwrite) was rejected: it falls back to non-atomic copy+delete on EXDEV, rejects directory sources, and throws UnauthorizedAccessException instead of errno IOExceptions. * Remove unused Xamarin.Android.Build.Tasks Utilities/FileUtil.cs and its rename P/Invoke. Co-authored-by: Copilot App <[email protected]>
uname() reports the "Darwin" sysname on watchOS too, so the managed
replacement for the uname P/Invoke must treat watchOS as Mac on both the
.NET (OperatingSystem.IsWatchOS) and netstandard2.0
(OSPlatform.Create ("WATCHOS")) paths.
Add a host test comparing OS.IsMac/IsLinux/IsWindows with the original
uname()-based classification.
Co-authored-by: Copilot App <[email protected]>
The runtime platform checks do not establish uname equivalence on unsupported platforms such as watchOS. Correct the comment without changing the detection logic. Co-authored-by: Copilot App <[email protected]>
The platform detection implementation now relies on runtime platform checks instead of calling uname(3). Remove the host-only comparison, which required a separate uname P/Invoke in the test suite. Co-authored-by: Copilot App <[email protected]>
AndroidAppManifest.WriteToFile remains public and uses the native rename helper. Cover non-ASCII paths and both new and existing destinations so the source-generated and netstandard marshalling paths preserve this behavior. Co-authored-by: Copilot App <[email protected]>
Context: 6b8fb8c AndroidAppManifest.WriteToFile() is the only production caller of FileUtil.SystemRename(), and no in-tree callers use the file-writing method. The manifest type is still used by build tasks, so retain it while removing the file writer and its native rename implementation. This removes a shipped public API. Consumers can use Write(XmlWriter) and manage file creation and replacement themselves. Record the removal in the public API baselines and remove tests for the deleted operations. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Removing the shipped public AndroidAppManifest.WriteToFile(string) API is binary-breaking and requires maintainer confirmation of downstream compatibility and release-policy acceptance.
No open issues 🎉
What changed in this PR
This PR simplifies Android SDK tooling by replacing native uname detection with managed platform checks and removing unused manifest-writing and rename code.
Changes:
- Uses runtime platform checks for Darwin classification, with watchOS equivalence explicitly unverified.
- Intentionally removes the shipped
AndroidAppManifest.WriteToFile(string)API;Write(XmlWriter)remains, with file creation and replacement left to callers. - Removes unused rename helpers, the duplicate build-task utility, and their tests. The chmod fallback and Windows interop remain unchanged.
| File | Description |
|---|---|
| tests/Xamarin.Android.Tools.AndroidSdk-Tests/SystemRenameTests.cs | Deletes tests for the removed rename helper. |
| tests/Xamarin.Android.Tools.AndroidSdk-Tests/FileUtilTests.cs | Removes rename-specific cases and an unused import. |
| src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt | Records the manifest writer API removal for netstandard2.0. |
| src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net11.0/PublicAPI.Unshipped.txt | Records the manifest writer API removal for net11.0. |
| src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net10.0/PublicAPI.Unshipped.txt | Records the manifest writer API removal for net10.0. |
| src/Xamarin.Android.Tools.AndroidSdk/OS.cs | Replaces uname interop with managed Apple-platform checks. |
| src/Xamarin.Android.Tools.AndroidSdk/FileUtil.cs | Removes temporary-name and rename helpers, including native interop. |
| src/Xamarin.Android.Tools.AndroidSdk/AndroidAppManifest.cs | Removes WriteToFile, retaining Write(XmlWriter). |
| src/Xamarin.Android.Build.Tasks/Utilities/FileUtil.cs | Deletes the unused duplicate utility. |
Review effort: Balanced
|
OS classification microbenchmark — earlier candidate On macOS arm64 with the .NET 11 runtime, 40 counterbalanced cold-process pairs compared main
These measure This measurement predates the later macOS-only simplification and does not measure the current PR head. |
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ Needs Changes — compatibility decision outstanding
Reviewed all nine changed files, their surrounding source, callers, and AndroidSdk target-framework configuration. 0 errors, 1 warning, 1 suggestion, posted inline. The warning asks for explicit downstream-compatibility/release acceptance of the intentional shipped WriteToFile(string) removal; absent that acceptance, preserve a compatibility entry point. The suggestion adds independent platform-classification coverage for both target-framework paths.
The managed Darwin checks remove the unmanaged allocation and uname call while retaining the existing Windows/non-Darwin classification on supported desktop hosts. No in-repository callers of the removed writer or rename helpers remain. The API-removal records are consistent across all three existing framework baselines, and the chmod fallback and Windows interop are unchanged. The description clearly distinguishes the API break and watchOS limitation; no additional correctness defect was identified in the remaining implementation.
CI: All 41 GitHub check runs report success, including the aggregate dotnet-android check for Azure build 1673052. Direct Azure build/timeline verification was blocked by CLI startup and authentication errors, so Azure status was not independently confirmed. No local builds or tests were run for this read-only review.
Generated by Android PR Reviewer for #13457 · copilot · gpt61 · 31.3 AIC · ⌖ 7.63 AIC · ⊞ 19.5K
Comment /review to run again
| @@ -1,4 +1,5 @@ | |||
| #nullable enable | |||
| *REMOVED*Xamarin.Android.Tools.AndroidAppManifest.WriteToFile(string! fileName) -> void | |||
There was a problem hiding this comment.
🤖 AndroidAppManifest.WriteToFile(string) will fail with MissingMethodException after upgrading. The description correctly acknowledges this, but Write(XmlWriter) is neither a binary-compatible replacement nor an equivalent file-replacement API. Unless the break is approved for this release, retain an obsolete compatibility entry point and preserve its replacement behavior. This applies to the net10.0 and net11.0 removals as well.
{Rule: Shared tooling API-shape changes require downstream binary-compatibility review.}
There was a problem hiding this comment.
The API removal remains intentional and was explicitly requested by the PR author after confirming there are no in-repository callers. A compatibility entry point would retain the file-writing/rename behavior this change is removing. I cannot independently confirm downstream compatibility or release-policy acceptance, so I am leaving this thread open for maintainer review of that release decision.
Auto-replied by the GitHub Copilot app
Add independent runtime-platform assertions for the OS classification and native library format. Run the test with both the netstandard2.0 and modern .NET AndroidSdk assemblies. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ Needs Changes — outstanding compatibility decision
Reviewed all 10 changed files, the removed implementations, callers, target-framework configuration, and the Android tools test pipeline at 877d1f2f1c2ff65d34cf682a9516ec88359bfa37. New findings: 0 errors, 0 warnings, 1 documentation suggestion, posted inline. No additional correctness defects found.
The existing unresolved API-design thread still needs a maintainer decision: removing the shipped AndroidAppManifest.WriteToFile(string) breaks downstream source/binary compatibility, even though no in-repository callers remain. The PR accurately acknowledges both that intentional break and the unsupported-platform/watchOS limitation; I have not duplicated the existing compatibility finding.
The managed platform checks remove the unmanaged allocation and uname call without changing the constructor's Windows/non-Apple fallback logic. The new platform-classification test addresses the previous testing feedback, and the removed rename tests correspond to functionality that is actually deleted. The chmod fallback and Windows interop are unchanged.
CI: All 40 head-commit GitHub checks report success, including the aggregate dotnet-android check and Windows/macOS Android Tools Tests. A direct query of Azure build 1675489 failed because az devops invoke requires authentication in this environment, so independent Azure build/timeline verification is incomplete. No local builds or tests were run for this review.
Generated by Android PR Reviewer for #13457 · copilot · gpt61 · 37.4 AIC · ⌖ 4.14 AIC · ⊞ 20.2K
Comment /review to run again
Co-authored-by: Copilot App <[email protected]>
Context: #13457 Android SDK tooling runs on desktop development hosts and does not need to classify iOS, tvOS, watchOS, or Mac Catalyst as macOS. Replace the private helper with a direct RuntimeInformation.IsOSPlatform (OSPlatform.OSX) check for both target frameworks. Keep Windows detection and the existing fallback for other platforms. Co-authored-by: Copilot App <[email protected]>
Context: #13457 Removing AndroidAppManifest.WriteToFile breaks existing callers. Document how consumers can migrate to Write(XmlWriter), and explain why writing directly to the destination does not preserve the old temporary-file replacement behavior. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ Needs Changes — existing compatibility decision remains open
Reviewed all 10 changed files and searched the repository for callers of the removed APIs. No new correctness defects found. New findings: 0 errors, 0 warnings, 1 documentation suggestion (inline).
The RuntimeInformation.IsOSPlatform(OSPlatform.OSX) replacement fits the desktop-host scope and the netstandard2.0 target. Removing the writer together with both unused rename implementations avoids silently changing replacement semantics. The API removal is recorded for all three target frameworks, and the new README clearly explains the binary break and direct-write truncation risk.
The existing API-compatibility thread remains unresolved: intentional removal and absence of in-tree callers do not establish release-policy acceptance for downstream binaries. I have not duplicated that finding or the platform-test suggestion already considered in the earlier review.
CI: All 40 head-commit GitHub checks report success, including the overall dotnet-android check for Azure build 1679285. Direct Azure build/timeline verification was blocked because az devops invoke requires authentication in this environment, so that part of CI verification is incomplete. GitHub also currently reports merge conflicts (mergeable_state: dirty).
Generated by Android PR Reviewer for #13457 · copilot · gpt61 · 34.2 AIC · ⌖ 5.19 AIC · ⊞ 21K
Comment /review to run again
jonathanpeppers
left a comment
There was a problem hiding this comment.
I'm good with removing the p/invoke, but we can keep the public API still. 👍
Restore the public WriteToFile API and write directly to the destination file with XmlWriter, so the rename p/invoke is not needed. Revert the README and PublicAPI changes. Co-authored-by: Copilot App <[email protected]>
…ative-interop-review # Conflicts: # src/Xamarin.Android.Tools.AndroidSdk/FileUtil.cs # src/Xamarin.Android.Tools.AndroidSdk/OS.cs
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed 03912cd3 against main at f9c38dcb, which is also the merge-base. This was a static, read-only review. I didn't build or run anything.
LGTM. Switching OS to RuntimeInformation.IsOSPlatform(OSPlatform.OSX) keeps the same IsWindows/IsMac/IsLinux results. Windows is still checked first, and the static constructor gains no new way to fail. AndroidAppManifest.WriteToFile(string) keeps its public signature and its XmlWriterSettings (UTF-8 BOM, tab indent, \n), and XmlWriter.Create(path) truncates the existing file. Writing directly to the destination is the tradeoff you agreed on in this thread. The deleted Build.Tasks FileUtil was a separate internal copy. Build.Tasks only takes a ProjectReference on AndroidSdk and doesn't link its sources, and nothing left in the tree calls SystemRename or GetTempFilenameForWrite. Every removed member was internal or private, and the removed tests only covered SystemRename.

Context: #10763
Context: #12988
Context: #13375
Xamarin.Android.Tools.AndroidSdk.OScallsuname()and allocates an unmanaged buffer to determine whether the host is Darwin. Android SDK tooling runs on desktop development hosts, so useRuntimeInformation.IsOSPlatform (OSPlatform.OSX)directly instead. The Windows check and the fallback for non-Windows, non-macOS hosts remain unchanged; separate checks for iOS, tvOS, watchOS, and Mac Catalyst are not needed.FileUtil.SystemRename()is used in production only byAndroidAppManifest.WriteToFile(). Its Unixrename()and Windows backup/restore paths have different semantics from a managed file move. Keep the publicWriteToFile(string)API, but write directly to the destination withXmlWriter.Create (fileName, ...)and remove the rename helpers. Also remove the unused duplicate build-tasksFileUtil.Compatibility: The public API does not change.
WriteToFile()no longer writes to a temporary file first, so a serialization failure can leave the destination file incomplete.The chmod fallback and Windows path/registry interop are unchanged. #10763 migrated different runtime P/Invokes. #12988 changes the SDK chmod fallback and targeting, and #13375 adds safety annotations to the removed declarations. Neither is a prerequisite, but both touch these files and may need rebasing.
Validation
After restoring
WriteToFile()(a2839ac), on Windows x64:dotnet build src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj— passed, 0 warnings.dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj --filter 'FullyQualifiedName~AndroidAppManifest|FullyQualifiedName~FileUtil|FullyQualifiedName~OS'— 28 passed, 4 skipped.Before that change, on macOS arm64, using a session-owned toolchain and home, with main
6b8fb8c3742b8ea4aa5f9f92e70a601a28f83360as the baseline:make leeroy MSBUILD_ARGS=-p:IncludeAndroidJavadoc=true— passed; two source-control/SourceLink warnings../dotnet-local.sh test bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter 'FullyQualifiedName~RemoveDirTests|FullyQualifiedName~BuildTest2.NonAndroidNativeLibrariesDoNotProduceWarnings' -v minimal— 7 passed, 4 skipped.dotnet build src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj -c Release -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=11.0 -v minimal— passed for net11.0 and netstandard2.0.dotnet build src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj -c Release -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0 -v minimal— passed for net10.0 and netstandard2.0.dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=11.0 -v minimal— 536 passed, 8 skipped.dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0 -v minimal— 536 passed, 8 skipped.dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=true -p:DotNetTargetFrameworkVersion=11.0 --filter 'FullyQualifiedName!~CreateProcessStartInfo_SingleArg&FullyQualifiedName!~CreateProcessStartInfo_MultipleArgs&FullyQualifiedName!~CreateProcessStartInfo_ArgWithSpaces' -v minimal— 529 passed, 8 skipped. The three excludedProcessUtilsTestsargument-list failures also reproduce against the saved main-baseline assembly.A session-only probe verified macOS classification and native-library format on arm64 and x64/Rosetta for all three target frameworks.
Performance
The paired OS-constructor benchmark measured intermediate commit
9e977cbdf7, not the current PR head. Median times were 841.9 → 163.1 µs for net11.0 and 834.5 → 179.4 µs for netstandard2.0. These are class-constructor timings, not application startup or build times. Final-head timing was deferred due to host contention; no speedup is claimed for the current head.