Skip to content

feat: support for unity as a library on Android - #2895

Merged
bitsandfoxes merged 59 commits into
mainfrom
feat/uaal-android
Oct 29, 2026
Merged

bitsandfoxes merged 59 commits into
mainfrom
feat/uaal-android

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds experimental support for Unity as a Library on Android, on top of the iOS support in #2885. A native Android app that embeds the game and already ships sentry-android gets the game's errors, crashes and logs in the same release, environment, user and trace as its own, without bundling a second SDK.

Set AndroidNativeInitializationType = NativeInitializationType.External in the Unity options. The app depends on io.sentry:sentry-android 8.49.0 or newer and starts it as usual. Nothing else is needed in the app.

How it works:

  • The export ships no sentry-android AARs and writes no io.sentry.* manifest entries: unityLibrary's manifest merges into the app's, and today's io.sentry.auto-init=false would turn off an app that relies on auto-init. The ProGuard rules stay as consumer rules, so the app's R8 keeps the classes the game calls by name.
  • At runtime the game attaches when sentry-android is already running in its process (Unity in the app's main process). That works as on iOS: no init, no close, nothing written to the app's scope that it owns, and C# events use the app's release, environment, user and trace.
  • When the game runs in its own process (android:process=":Unity", as in Unity's UaaL sample), the app's SDK doesn't exist there. The game starts sentry-android itself with the options set in Unity, and it:
    • uses its own cache directory (cache/sentry-<process>), so it doesn't end the app's session or overwrite its persisted scope;
    • takes the release, environment, user and trace from what the app's SDK persisted (cache/sentry/<dsn hash>/.options-cache, .scope-cache), at start and on every resume. A release or environment the game sets itself wins, in the options or through the Editor's override fields, even when it matches the default (as on iOS). A file it can't read, e.g. while the app's SDK rewrites it, keeps the previous trace and user;
    • leaves ANRs and tombstones to the app's SDK from API 30, which reads the exits of all of the app's processes. A second reader would report each one twice.
  • In the main process without a running SDK, the game logs a warning and reports C# only.
  • C# sessions are off: the app tracks sessions.
  • App hang heartbeats skip while the game is paused. Unity renders a few frames after losing focus, and a heartbeat in them re-armed sentry-native's paused detector, so a game paused behind the app reported a false app hang. On resume a heartbeat goes out right away, so detection is back before the next tick. This applies to every platform that uses sentry-native's app hang detection: on desktop, detection now stays off while the window is out of focus.
  • The symbol upload moves to unityLibrary/build.gradle and runs after merge<Variant>JniLibFolders, since the app never builds launcher.

Verified on a Pixel 6 (Android 16) with a host app on sentry-android 8.59.0, in both layouts:

Scenario Result
Symbol upload during the app's Gradle build uploaded, IL2CPP mappings resolved
App event and log before Unity loads ✅
C# message, LogError, caught and unhandled exceptions, logs app's release, environment, user and trace, IL2CPP line numbers
Native crash from a C++ plugin symbolicated, C# frames (NativeButtons.cs:53), app's user and trace
Native crash, Unity in the main process app's user and tags, unity context, same trace
unload() and show again same process, no re-init
Quit and show again fresh init, pending crash sent

Known limits:

  • In its own process the game calls sentry-android options added in 8.49.0. With an older sentry-android in the app, its setup stops partway and the game shares the app's cache directory and session.
  • A native crash in the game's own process is sent the next time the game starts, not by the app's SDK. A game that's never opened again never reports it.
  • In its own process the game only follows the app's trace, user and options when its DSN is the app's (same DSN hash directory). It reads them at start and on resume, so a change in the app while the game is in front shows up on the next resume.
  • Only SentrySdk.StartTransaction(name, op) joins the app's trace (as on iOS).
  • Utils.ForceCrash called from a one-line method has no C# frame: IL2CPP compiles it to a tail call.
  • Upstream ask: sentry-java could filter exit infos by process and suffix the cache directory of non-main processes itself.

Sentry.Unity.Android.dll now loads in the Editor in package-dev, as Sentry.Unity.iOS.dll does, so Sentry.Unity.Android.Tests runs in the Editor test runs. The release package still ships it for Android only.

Builds on #2885, which is merged into main. The CHANGELOG has one entry for both platforms. #2885 added it for iOS, and this PR extends it to Android.

Part of #2416.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against e6be7d1

@bitsandfoxes bitsandfoxes changed the title Add Unity as a Library support on Android feat: support for unity as a library on Android Oct 22, 2026
…game's own process instead of sentry-java's defaults
…cribe the release, environment and ANR handling
@bitsandfoxes
bitsandfoxes marked this pull request as ready for review October 28, 2026 11:35
@bitsandfoxes
bitsandfoxes requested review from a team, jpnurmi, limbonaut and tustanivsky October 28, 2026 11:35

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cac9cef. Configure here.

Comment thread src/Sentry.Unity.Android/SentryJava.cs Resolved
Base automatically changed from feat/uaal to main October 29, 2026 16:03
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