Skip to content

[ci-fix] Fix Android NativeAOT template for updated memory safety rules - #134323

Closed
simonrozsival wants to merge 1 commit into
mainfrom
simonrozsival-fix-android-unsafe-build
Closed

simonrozsival wants to merge 1 commit into
mainfrom
simonrozsival-fix-android-unsafe-build

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • remove type-level unsafe modifiers that are invalid under the updated C# memory-safety rules
  • add scoped unsafe blocks around JNI and native interop operations
  • explicitly mark the pointer-bearing native declarations unsafe and document their caller safety contracts

This is closely related to #134134, which fixed the equivalent Apple NativeAOT build break. The Apple imports were correctly marked safe because they synchronously copy managed string inputs and impose no obligation on callers. The Android imports remain unsafe because the native implementations dereference or retain the supplied JavaVM* and argv pointers.

@matouskozak noticed the Android failure in runtime-extra-platforms build 1604366.

Validation

  • ./build.sh tasks
  • Android arm64 NativeAOT libraries and test APK build, using the CI command with /p:StripSymbols=false because the local environment does not have llvm-objcopy
    • built and published both System.Text.Json.SourceGeneration.Roslyn3.11.Tests and System.Text.Json.SourceGeneration.Roslyn4.4.Tests
    • completed with zero warnings and zero errors

Note

This pull request description was generated with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 21, 2026 08:10
@simonrozsival simonrozsival changed the title Fix Android NativeAOT template for updated memory safety rules [ci-fix] Fix Android NativeAOT template for updated memory safety rules Sep 21, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Updates the Android NativeAOT template for revised C# memory-safety rules.

Changes:

  • Scopes JNI and pointer operations in unsafe blocks.
  • Marks pointer-bearing native declarations unsafe.
  • Removes obsolete type-level unsafe modifiers.
File Description
src/​tasks/​AndroidAppBuilder/​Templates/​monodroid-nativeaot.cs Applies updated unsafe-context and interop safety annotations.

@simonrozsival

Copy link
Copy Markdown
Member Author

Closing as a duplicate of #134212, which predates this PR and implements the same updated memory-safety migration. #134115 tracks the Android NativeAOT build break.

Note

This comment was generated with GitHub Copilot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants