Skip to content

fix(android): add explicit JNI activation constructor to OsuGameActivity - #321

Merged
winnerspiros merged 1 commit into
masterfrom
copilot/fix-osu-android-crash-another-one
May 9, 2026
Merged

fix(android): add explicit JNI activation constructor to OsuGameActivity#321
winnerspiros merged 1 commit into
masterfrom
copilot/fix-osu-android-crash-another-one

Conversation

Copilot AI commented May 9, 2026

Copy link
Copy Markdown

v226 crashes at launch with NotSupportedException: Could not activate JNI Handle ... as managed type 'osu.Android.OsuGameActivity' — thrown by TypeManager.Activate when it can't find the (IntPtr, JniHandleOwnership) constructor on the concrete activity type.

Why the v225 Linker.xml fix wasn't sufficient

Linker.xml already has <assembly fullname="osu.Framework.Android" preserve="all" /> to protect AndroidGameActivity's inherited JNI constructor. But ILLink emits IL2007 for that entry at descriptor-processing time (the NuGet assembly isn't in the link set yet), and the deferred preserve path proved unreliable for protecting inherited constructors in the concrete subtype — confirmed by the v226 field crash.

Fix

Declare the JNI activation constructor explicitly on OsuGameActivity itself:

protected OsuGameActivity(IntPtr handle, JniHandleOwnership transfer)
    : base(handle, transfer)
{
}

osu.Android is preserve="all" and always resolvable at descriptor-processing time, so ILLink unconditionally keeps this constructor. TypeManager.Activate finds it directly on the concrete type without traversing into the deferred-rule assembly.

@gitar-bot

gitar-bot Bot commented May 9, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@winnerspiros
winnerspiros marked this pull request as ready for review May 9, 2026 07:03
Copilot AI review requested due to automatic review settings May 9, 2026 07:03
@winnerspiros
winnerspiros merged commit 11c4af0 into master May 9, 2026
21 of 23 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

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 addresses an Android launch crash caused by TypeManager.Activate failing to find the required JNI activation constructor on osu.Android.OsuGameActivity after linking/trimming.

Changes:

  • Add an explicit (IntPtr, JniHandleOwnership) JNI activation constructor to OsuGameActivity to ensure it survives trimming and is discoverable on the concrete activity type.
  • Expand Linker.xml commentary to document why relying on deferred ILLink rules for osu.Framework.Android can be insufficient, and why the concrete-type constructor is an added safeguard.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
osu.Android/OsuGameActivity.cs Adds the explicit JNI activation constructor on the concrete Activity type to prevent runtime activation failures under trimming.
osu.Android/Linker.xml Documents the rationale for the additional defense and the limitations of IL2007-deferred preservation for NuGet-provided assemblies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants