Repository navigation
[native] Simplify NativeAOT host and remove unused shared library - #13281
Conversation
NativeAOT applications link the host archive, not a standalone host shared library. The shared target only adds unused artifacts to local SDK packs; published runtime NuGets already select the static archives. Consolidate startup, JNI entry points, and property lookup in host.cc, remove obsolete wrappers and unused sources, and standardize the native entry point names. Preserve the hidden DT_INIT hook so environment data is applied before NativeAOT constructors, and retain weak references only for optional remapping data. Build static hosts only, track both configuration archives as native outputs, and remove obsolete shared hosts from native output and local packs before wildcard copying. Extend pack and application-link tests. Validation: native/task builds; 7 link/pack regressions; 14 property-reader tests; and 11 RuntimeInitialization tests on an ARM64 Android emulator. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
🔵 Needs a closer look
The DT_INIT/JNI bootstrap consolidation affects native startup and managed/native linkage, but reported device execution covers only ARM64, leaving ARM and x64 startup unverified and requiring human validation.
No open issues 🎉
What changed in this PR
Simplifies the .NET for Android NativeAOT host by consolidating its implementation and removing the unused shared-library build, while retaining the static archives used by applications.
Changes:
- Consolidates startup, JNI entry points, and property lookup in
host.cc, with consistentNativeAOT_*names. - Removes shared-host build scaffolding, tracks static archive outputs, and cleans stale shared libraries from local packs.
- Extends regression coverage for application linking, pack contents, and stale-file cleanup.
| File | Description |
|---|---|
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs |
Extends static-linking, pack-content, and cleanup assertions. |
src/native/nativeaot/runtime-base/android-system.cc |
Moves property lookup into host.cc. |
src/native/nativeaot/libnaot-android.map.txt |
Removes the shared-host export map. |
src/native/nativeaot/include/shared/log_types.hh |
Removes the redundant logging header. |
src/native/nativeaot/include/runtime-base/app-system-properties.hh |
Removes the remapping helper declaration. |
src/native/nativeaot/include/host/host-nativeaot.hh |
Removes the forwarding host class. |
src/native/nativeaot/include/host/host-jni.hh |
Removes obsolete JNI entry-point declarations. |
src/native/nativeaot/include/host/host-environment-variables.hh |
Removes obsolete environment-header scaffolding. |
src/native/nativeaot/include/host/host-environment-naot.hh |
Removes the forwarding environment header. |
src/native/nativeaot/host/host.cc |
Consolidates initialization, JNI handling, and property lookup. |
src/native/nativeaot/host/host-jni.cc |
Moves JNI entry points into host.cc. |
src/native/nativeaot/host/host-environment.cc |
Moves system-property setup into host.cc. |
src/native/nativeaot/host/host-bootstrap.cc |
Moves bootstrap and remapping logic into host.cc. |
src/native/nativeaot/host/CMakeLists.txt |
Retains only the static host target and required sources. |
src/native/native.targets |
Tracks static archives and removes stale shared hosts. |
src/native/clr/runtime-base/binary-blob-loader.cc |
Removes an unnecessary logging include. |
src/native/clr/include/host/host-environment.hh |
Removes the obsolete initialization declaration. |
src/Microsoft.Android.Runtime.NativeAOT/Android.Runtime.NativeAOT/JavaInteropRuntime.cs |
Updates managed imports to the renamed native entry points. |
src/Microsoft.Android.Build.Tasks/Tasks/LinkNativeAotSharedLibrary.cs |
Updates linker arguments for the renamed initialization hook. |
Review effort: Balanced
There was a problem hiding this comment.
⚠️ CI pending — no blocking code findings
Reviewed all 19 changed files, including deleted sources, and traced the managed imports, direct-P/Invoke configuration, linker arguments, CMake inputs, and runtime-pack consumers. The NativeAOT_* renames are consistent across callers and definitions. The static-only host preserves the hidden DT_INIT callback, strong bootstrap symbols, weak optional remapping symbols, and ownership-safe duplication of borrowed JNI strings. Package selection already explicitly consumes the static archives.
Findings: 0 errors, 0 warnings, 1 optional inline testing suggestion for multi-RID stale-library cleanup coverage. The updated link and packaging assertions directly cover the removed shared-host artifact and retained static-link contract.
CI: The returned checks show five Azure DevOps lanes running and the aggregate check queued for build 1650930; CLA and the earlier reviewer workflow passed. No returned check is failing, but CI is not yet green. The Azure build-details query failed because the CLI requires authentication, so pipeline timeline/results could not be independently confirmed. Local builds/device tests were not rerun during this review; the validation results in the PR description remain author-reported.
Generated by Android PR Reviewer for #13281 · copilot · gpt61 · 32.6 AIC · ⌖ 7.9 AIC · ⊞ 19.3K
Comment /review to run again
jonathanpeppers
left a comment
There was a problem hiding this comment.
RuntimePackDoesNotContainCPlusPlusArchives(NativeAOT) failed, which may just need updating.
Context: #13281 RuntimePackDoesNotContainCPlusPlusArchives(NativeAOT) passes with a full local build but fails in CI because neither host archive is included in the test-generated package. The CI test jobs have installed runtime packs, but not the raw native build outputs that the pack project conditionally includes. Stage the Debug and Release host archives from the installed runtime pack and point NativeRuntimeOutputRootDir at the isolated fixture. Preserve the archive and obsolete shared-library assertions without depending on native source-build outputs. Co-authored-by: Copilot App <[email protected]>
Context: #13281 (comment) The stale-library fixture populated only android-arm64, so it could not detect cleanup processing only one item batch. Populate ARM, ARM64, and x64 together, verify stale files are removed from every source and pack directory, and check RID-specific retained contents and NDK builtins. Run runtime-pack content assertions for both NativeAOT and CoreCLR on all three RIDs. Keep the existing three-ABI NativeAOT application-link coverage, including DT_INIT, static host selection, hidden bootstrap symbols, and ARM EHABI handling. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ CI pending — no blocking code findings
Findings: 0 ❌ errors · 0
Reviewed all 19 changed files and traced the affected native/managed startup and packaging paths. The NativeAOT_* renames are consistent across native definitions, managed imports, and linker arguments. The hidden DT_INIT hook, strong bootstrap/weak remapping references, and borrowed JNI-string ownership are preserved. Tracking both static archives as build outputs matches the static-only CMake target. The expanded cleanup fixture also addresses the earlier review by exercising all three RIDs together and checking retained contents and architecture-specific builtins.
CI: At review time, checks for head efea97c3ed89b5fe2b652ac4c3885cf910153ceb point to Azure DevOps build 1652424. Linux Build, Android Tools Tests Windows, and CLA have passed; macOS Build, Windows Build & Smoke Test, and Android Tools Tests Mac remain in progress, with the aggregate check queued. No reported check is failing, but CI is not yet green. Azure DevOps build/timeline inspection was blocked in this environment, so this assessment is limited to the GitHub check results. The local validation results in the PR description were not independently rerun.
Generated by Android PR Reviewer for #13281 · copilot · gpt61 · 36.8 AIC · ⌖ 7.67 AIC · ⊞ 19.3K
Comment /review to run again
|
@dalexsoto review |
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
Code assessment: no blocking findings. 0 ❌ errors, 0
The native definitions, managed direct P/Invokes, and linker arguments consistently use the renamed entry points. The consolidation preserves early bootstrap initialization through hidden DT_INIT, strong required bootstrap symbols, weak optional remapping symbols, and ownership-safe duplication of borrowed JNI strings. Static archive selection matches the existing application-link and NuGet-pack paths. The multi-RID cleanup fixture checks retained file contents as well as architecture-specific toolchain assets.
CI: All 41 GitHub checks on efea97c3ed89b5fe2b652ac4c3885cf910153ceb report completed/success, including the aggregate dotnet-android check for Azure build 1652424. Independent Azure build-result/timeline verification is incomplete: the read-only az devops invoke build query requires authentication in this environment. No Azure-side result beyond the GitHub checks is claimed.
Generated by Android PR Reviewer for #13281 · copilot · gpt61 · 38.6 AIC · ⌖ 7.95 AIC · ⊞ 19.3K
Comment /review to run again
| "AndroidRID=android-arm64", | ||
| $"AndroidRID={rid}", | ||
| $"_MonoAndroidNETOutputRoot={managedOutputRoot}{Path.DirectorySeparatorChar}", | ||
| $"NativeRuntimeOutputRootDir={nativeOutputRoot}{Path.DirectorySeparatorChar}", |
There was a problem hiding this comment.
🤖 💡 Testing — Consider staging the CoreCLR native assets under runtime-output/coreclr/{rid} as well, and asserting that the resulting package contains libnet-android.release.so. This override now points every case at the isolated output root, but only the NativeAOT cases populate it. For CoreCLR, _GetRuntimePackItems skips the host assets through its Exists(...) conditions, so those three cases can pass with no CoreCLR host in the package. A positive host-presence assertion would keep the exclusion checks from passing on an incomplete fixture.
{Rule: Test assertions must be specific}
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed all 19 changed files: NativeAOT host, build, packaging and test changes with their initialization, JNI ownership, symbol and native-archive consumers, including a separate final independent-blocker search.
The consolidated NativeAOT host preserves initialization, ownership, symbol and static-archive packaging contracts. No independent high-confidence blocker remains.
The all-RID cleanup and static-host packaging policies remain intentional; author-reported device and package results are not independent execution.
This is a bounded static-source review, not an independently executed build, device test, produced-output or latest-target certification.
Context: #13116
Context: #10461
Simplify the host
After the internal P/Invoke removal, the NativeAOT-specific host still spreads a small amount of startup code across forwarding classes, JNI wrappers, environment helpers, and bootstrap files. These layers no longer provide a useful separation: the host applies bootstrap environment data, supplies native JNI initialization, and connects the GC bridge.
Consolidate that glue into
host.cc, remove the forwarding headers and unused CoreCLR source inputs, and use consistentNativeAOT_*entry-point names in the native definitions, managed imports, and linker arguments. Keep the bootstrap property reader out of line inapp-system-properties.cc.The early environment callback remains hidden and selected through
DT_INIT, so environment variables are applied before NativeAOT's constructors run. Required bootstrap symbols remain strong, optional remapping symbols remain weak, and the JNI wrappers continue to duplicate borrowed string references before taking ownership.Remove the unused shared host
The NativeAOT host has built both static and shared libraries since its introduction in #10461, but applications have selected the static archive from the beginning. The shared library's export map exposes no API, and no runtime consumer was found. The NuGet pack project also explicitly selects only the host archives: the checked published ARM64 packages
36.0.0-rc.2.332,36.1.2,36.1.118, and37.2.0-rc.2.84contain those archives, notlibnaot-android*.so. The shared libraries reach local SDK packs through the native output copy wildcard instead.Build only the static host archives and remove the shared target, export map, and
DYNAMIC_RUNTIME_LINKINGbranches. Track both Debug and Release archives as native build outputs instead of using the unused shared library as an incremental-build sentinel. Delete stale shared hosts from native output and local runtime packs before wildcard copying, so an existing checkout does not keep copying artifacts that are no longer built.This removes an unused local-build artifact, not a shared host shipped by the checked published runtime NuGets. The static host and its application-link contract remain in place. No linked issue is being closed.
Validation
Release native/task builds pass. The expanded host regression suite passes all 11 cases: NativeAOT application linking on ARM, ARM64, and x64; runtime-pack contents on all three RIDs for both NativeAOT and CoreCLR; and stale-library cleanup with all three RIDs populated in the same MSBuild invocation. Cleanup verifies RID-specific retained file contents and architecture-specific NDK builtins, not just file existence. The bootstrap reader passes all 14 cases.
NativeAOT runtime execution now covers all three supported ABIs:
android-armRuntimeInitializationtests passed on a physical Android device, 0 skipped. The installed package reportsprimaryCpuAbi=armeabi-v7aandsecondaryCpuAbi=null, confirming actual 32-bit ARM execution.android-arm64RuntimeInitializationtests previously passed on a local ARM64 emulator.android-x64Mono.Android.NET_Tests-NativeAOT, run 45940116). Later commits change tests only.Commands and results
./dotnet-local.sh build src/native/native-nativeaot.csproj -c Release --no-restore -v:quiet- passed../dotnet-local.sh build src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj -c Release --no-restore -v:quiet- passed../dotnet-local.sh build src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj -c Release --no-restore --disable-build-servers -v:quiet- passed../dotnet-local.sh test bin/TestRelease/net10.0/Xamarin.Android.Build.Tests.dll --filter 'Name~BuildNativeAotWithoutCPlusPlusArchives|Name~CopyRuntimePackRemovesStaleNativeLibraries|Name~RuntimePackDoesNotContainCPlusPlusArchives' -v minimal- 11 passed, 0 skipped; the run additionally enabled TRX logging to the session artifact directory.dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -c Release --filter 'FullyQualifiedName~NativeAotSystemPropertiesTests' -v minimal- 14 passed../dotnet-local.sh build -t:Install -c Release tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:PublishAot=true -p:RuntimeIdentifier=android-arm64 -p:IncludeCategories=RuntimeInitialization '-p:AdbTarget=-s emulator-5574' --disable-build-servers -v:quiet- passed, with existing trimming/AOT warnings.tests/Mono.Android-Tests/Mono.Android-Tests:../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release -p:PublishAot=true -p:RuntimeIdentifier=android-arm64 -p:IncludeCategories=RuntimeInitialization '-p:AdbTarget=-s emulator-5574' --device emulator-5574 --report-trx --results-directory ../../../bin/TestRelease/TestResults/NativeAotBootstrapRenameRepacked- 11 passed.run Mono.Android.NET_Tests-NativeAOT:dotnet test Mono.Android.NET-Tests.csproj -c Release --report-trx --output Detailed -p:TestsFlavor=NativeAOT -p:PublishAot=truewith the pipeline's binlog/results-file arguments - 851 passed, 7 skipped, 0 failed on x64.For the physical ARM device,
$ARM_DEVICEdenotes its ADB serial and$RESULTS_DIRECTORYthe session-local TRX output directory:./dotnet-local.sh restore tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:Configuration=Release -p:PublishAot=true -p:RuntimeIdentifier=android-arm -p:IncludeCategories=RuntimeInitialization --disable-build-servers -v:quiet- passed. The initial--no-restorebuild reported NETSDK1047 because the previous restore contained onlyandroid-arm64; restoring forandroid-armresolved it without source changes../dotnet-local.sh build -t:Install -c Release tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj --no-restore -p:PublishAot=true -p:RuntimeIdentifier=android-arm -p:IncludeCategories=RuntimeInitialization "-p:AdbTarget=-s $ARM_DEVICE" --disable-build-servers -v:quietwith a session-local binlog - passed, with existing trimming/AOT warnings.tests/Mono.Android-Tests/Mono.Android-Tests:../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release -p:PublishAot=true -p:RuntimeIdentifier=android-arm -p:IncludeCategories=RuntimeInitialization "-p:AdbTarget=-s $ARM_DEVICE" --device "$ARM_DEVICE" --report-trx --results-directory "$RESULTS_DIRECTORY"- 11 passed, 0 skipped, after approving installation on the phone.adb -s "$ARM_DEVICE" shell 'dumpsys package Mono.Android.NET_Tests | grep -E "primaryCpuAbi|secondaryCpuAbi|nativeLibraryDir"'- reportsprimaryCpuAbi=armeabi-v7aandsecondaryCpuAbi=null.Initial local ARM64 runs used a cached old linker task and a stale test bundle, causing startup to abort. After using a fresh MSBuild process and regenerating the stale bundle, the packaged library contains
DT_INITand all 11 startup tests pass.Pull Request title and description should follow the
commit-messages.mdworkflow documentation, and in particular should include: