Skip to content

fix(android): add JNI activation constructor to OsuGameActivity to fix startup crash - #324

Merged
winnerspiros merged 1 commit into
masterfrom
copilot/fix-android-apk-crash-again
May 9, 2026
Merged

fix(android): add JNI activation constructor to OsuGameActivity to fix startup crash#324
winnerspiros merged 1 commit into
masterfrom
copilot/fix-android-apk-crash-again

Conversation

Copilot AI commented May 9, 2026

Copy link
Copy Markdown

TypeManager.Activate in .NET Android resolves (IntPtr, JniHandleOwnership) via GetConstructor on the concrete managed type — it does not walk the inheritance chain. OsuGameActivity never defined this constructor, so activation always fell through and threw NotSupportedException on any Android-initiated instantiation (process death + recreation, back-stack restore).

The existing guards (preserve="all" for osu.Android, AndroidLinkSkip for osu.Framework.Android/SDL3-CS, [DynamicDependency] attributes) all protect the base class constructors from trimming but do nothing for a constructor that was never defined on the concrete type in the first place.

Changes

  • osu.Android/OsuGameActivity.cs — adds the required JNI activation constructor directly on OsuGameActivity:
protected OsuGameActivity(IntPtr javaReference, JniHandleOwnership transfer)
    : base(javaReference, transfer)
{
}

This is the standard .NET Android pattern: every concrete Java.Lang.Object subclass instantiatable by the Android runtime must declare this constructor explicitly on the concrete type, not just inherit it.

…to fix JNI activation crash

Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/0a7096f4-e29c-4d75-a84b-5d7de0b80ff1

Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
@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 11:29
Copilot AI review requested due to automatic review settings May 9, 2026 11:29
@winnerspiros
winnerspiros merged commit 3e87758 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

Fixes an Android startup crash during Android-initiated Activity recreation (e.g., process death / back-stack restore) by adding the required JNI activation constructor directly to OsuGameActivity, ensuring .NET Android’s TypeManager.Activate can instantiate the concrete managed type.

Changes:

  • Added OsuGameActivity(IntPtr, JniHandleOwnership) constructor forwarding to the base constructor.
  • Expanded inline comments to document why the constructor is required on the concrete type and how it relates to existing linker/trimming guards.

💡 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