Skip to content

Fix Android NativeAOT template for updated memory safety rules - #134212

Open
agocke wants to merge 1 commit into
dotnet:mainfrom
agocke:fix-androidappbuilder-unsafe-v2
Open

agocke wants to merge 1 commit into
dotnet:mainfrom
agocke:fix-androidappbuilder-unsafe-v2

Conversation

@agocke

@agocke agocke commented Sep 18, 2026

Copy link
Copy Markdown
Member

Fixes the Android NativeAOT build failure in the runtime-extra-platforms pipeline after System.Text.Json source-generation tests enabled updated-memory-safety-rules.

The Android test template relied on type-level unsafe contexts, which have no effect under the updated rules. Move the contexts to the pointer operations and add explicit unsafe contracts to the native imports. The template remains compatible with the legacy rules.

Validation:

  • ./build.sh tasks
  • Compiled the template with legacy memory safety rules
  • Compiled the template with updated memory safety rules
  • Compiled the SINGLE_FILE_TEST_RUNNER path with updated memory safety rules

Note

This PR description was generated with GitHub Copilot.

Move unsafe contexts from type declarations to the pointer operations and mark native imports with explicit unsafe contracts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e8bb4900-bf72-4876-b479-091185e5b89a
@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

🟡 Changes recommended

The template currently declares pointer types/members in non-unsafe types, which should not compile as written.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity

Open (2)
What changed in this PR

This PR updates the Android NativeAOT app template used by AndroidAppBuilder to accommodate the “updated memory safety rules” by moving unsafe contexts closer to the pointer operations and adding explicit unsafe contracts on native imports.

Changes:

  • Localizes unsafe usage to specific blocks around pointer operations in the template entrypoints.
  • Adds explicit unsafe modifiers to native import declarations (e.g., LibraryImport, DllImport) that use pointer types.
  • Adjusts JNI helper types to remove type-level unsafe (but the current diff leaves pointer members in non-unsafe types, which needs correction).
File Description
src/​tasks/​AndroidAppBuilder/​Templates/​monodroid-nativeaot.cs Refactors unsafe usage and interop declarations in the Android NativeAOT template to comply with updated memory-safety requirements.

Comment thread src/tasks/AndroidAppBuilder/Templates/monodroid-nativeaot.cs
Comment thread src/tasks/AndroidAppBuilder/Templates/monodroid-nativeaot.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants