Skip to content

feat: ANR (Android) and hang detection (iOS) reporting#122

Open
bobbyg603 wants to merge 2 commits into
mainfrom
feat/anr-hang-detection
Open

feat: ANR (Android) and hang detection (iOS) reporting#122
bobbyg603 wants to merge 2 commits into
mainfrom
feat/anr-hang-detection

Conversation

@bobbyg603
Copy link
Copy Markdown
Member

Summary

Adds ANR (Android) and fatal main-thread hang detection (iOS) reporting. Both features already exist in the native libraries — this PR pulls them in and wires them up.

Android — ANR

  • Updated bugsplat-android-release.aar to v1.3.0 (built from the v1.3.0 tag).
  • ANR detection is automatic — AnrReporter runs inside BugSplatBridge.initBugSplat(...), no API change. Reports arrive as Android.ANR.
  • Requires Android 11 (API 30+) at runtime; older OS versions are silently skipped while native crash reporting continues to work.
  • Active whenever UseNativeCrashReportingForAndroid is enabled.

iOS — fatal hang detection

  • Updated BugSplat.xcframework and BugSplat-macOS.dylib to bugsplat-apple v3.2.0.
  • enableHangDetection is set in the iOS bridge before [BugSplat start], coupled to UseNativeCrashReportingForIos. Reports arrive as App Hang (Fatal).
  • macOS hang detection is intentionally left off for now (dylib still bumped to v3.2.0 for version parity).

Sample

  • New Hang / ANR button and Event_HangNative().
  • _hangNativeIos() shows a confirmation alert (matching the bugsplat-apple example) explaining the force-quit-and-relaunch flow, then blocks the main thread with NSThread sleepUntilDate: — CPU-idle, unlike a spin loop.
  • Flattened all crash buttons to direct On Click wiring and retired the now-unused ForcedCrashEvent relay.

Misc

  • README documents ANR + hang detection.
  • Package version bumped to 4.1.0.

Verification

  • Android: Android.ANR report on an API 30+ device via the Hang button.
  • iOS: App Hang (Fatal) report — run without the Xcode debugger attached, since hang detection is suppressed under a debugger.

Closes #121

🤖 Generated with Claude Code

Both features already exist in the native libraries; this wires them up.

Android — ANR:
- Update bugsplat-android-release.aar to v1.3.0 (built from the v1.3.0 tag).
- ANR detection is automatic inside BugSplatBridge.initBugSplat(...);
  reports arrive as Android.ANR. Requires Android 11+ at runtime.
- Active when UseNativeCrashReportingForAndroid is enabled.

iOS — fatal hang detection:
- Update BugSplat.xcframework and BugSplat-macOS.dylib to bugsplat-apple v3.2.0.
- Set enableHangDetection in the iOS bridge before [BugSplat start], coupled
  to UseNativeCrashReportingForIos. Reports arrive as App Hang (Fatal).
- macOS hang detection intentionally left off for now.

Sample:
- Add Event_HangNative() and a Hang/ANR button.
- _hangNativeIos() shows a confirmation alert then blocks the main thread
  with NSThread sleepUntilDate:, matching the bugsplat-apple example.
- Flatten crash buttons to direct On Click wiring; retire the unused
  ForcedCrashEvent relay.

Docs/version:
- Document ANR and hang detection in README.
- Bump package version to 4.1.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 21, 2026 21:38
Copy link
Copy Markdown

Copilot AI left a comment

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 wires up ANR reporting on Android and fatal main-thread hang detection on iOS by updating the bundled native libraries and exposing sample/test hooks + documentation.

Changes:

  • Added native hang/ANR trigger path in the Unity sample (new “Hang: Native” button + Event_HangNative()).
  • Enabled iOS hang detection in the ObjC bridge before starting BugSplat.
  • Documented ANR + hang detection and bumped the package version to 4.1.0.

Reviewed changes

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

Show a summary per file
File Description
Samples~/my-unity-crasher/Scripts/ForcedCrashEvent.cs.meta Removes the old relay script meta (no longer used by the sample).
Samples~/my-unity-crasher/Scripts/ForcedCrashEvent.cs Removes the old relay script in favor of direct button wiring.
Samples~/my-unity-crasher/Scripts/ErrorGenerator.cs Adds Event_HangNative() + platform-specific native hang triggers.
Samples~/my-unity-crasher/Scenes/Sample.unity Updates sample scene UI wiring and adds a Hang/ANR button instance.
Samples~/my-unity-crasher/Prefabs/Button_ForceCrash.prefab Updates the shared button prefab structure after removing the relay component.
README.md Documents Android ANR reporting and iOS fatal hang detection behavior.
package.json Bumps Unity package version to 4.1.0.
Editor/IOS/ObjC/BugSplatBridge.mm Enables hang detection before [BugSplat start] and adds an iOS hang test hook with a confirmation alert.
Editor/IOS/Frameworks/BugSplat.xcframework/tvos-arm64/BugSplat.framework/Headers/BugSplat.h Updates vendored BugSplat headers (adds hang detection API).
Editor/IOS/Frameworks/BugSplat.xcframework/tvos-arm64_x86_64-simulator/BugSplat.framework/Headers/BugSplat.h Updates vendored BugSplat headers (adds hang detection API).
Editor/IOS/Frameworks/BugSplat.xcframework/tvos-arm64_x86_64-simulator/BugSplat.framework/_CodeSignature/CodeResources Updates framework code signature resources after header changes.
Editor/IOS/Frameworks/BugSplat.xcframework/macos-arm64_x86_64/BugSplat.framework/Versions/A/Headers/BugSplat.h Updates vendored BugSplat headers for macOS slice (hang detection API present).
Editor/IOS/Frameworks/BugSplat.xcframework/ios-arm64/BugSplat.framework/Headers/BugSplat.h Updates vendored BugSplat headers (adds hang detection API).
Editor/IOS/Frameworks/BugSplat.xcframework/ios-arm64_x86_64-simulator/BugSplat.framework/Headers/BugSplat.h Updates vendored BugSplat headers (adds hang detection API).
Editor/IOS/Frameworks/BugSplat.xcframework/ios-arm64_x86_64-simulator/BugSplat.framework/_CodeSignature/CodeResources Updates framework code signature resources after header changes.
Editor/IOS/Frameworks/BugSplat.xcframework/Info.plist Adjusts xcframework slice identifiers/platform variants (tvos device vs simulator entries).
Comments suppressed due to low confidence (1)

Samples~/my-unity-crasher/Scenes/Sample.unity:1864

  • This prefab instance removes component {fileID: 5305253083977984388} (ForcedCrashEvent) but still contains override modifications targeting it (category, OnForceCrash...). Clean up these stale overrides so the instance no longer references a removed component.

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

Comment on lines 258 to 264
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 5305253083977984388}
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName: Crasher.ForcedCrashEvent, Assembly-CSharp
m_MethodName: Event_OnForceCrash
m_Mode: 1
Comment on lines 854 to +860
- target: {fileID: 5305253083977984388, guid: de657baed6ab68e4e946d741cdbe94e2, type: 3}
propertyPath: category
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5305253083977984388, guid: de657baed6ab68e4e946d741cdbe94e2, type: 3}
propertyPath: OnForceCrash.m_PersistentCalls.m_Calls.Array.size
value: 0
Unity runs C# on its own player thread, not the Android main/UI thread.
BugSplatBridge.hang() blocked the Unity thread, leaving the main thread
responsive, so the OS never registered an ANR. Dispatch the hang via
Activity.runOnUiThread so the main thread is the one that stalls.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

ANR and Hang Detection Reporting for Mobile

3 participants