Skip to content

fix Android StackOverflowError in MainApplication.getPackages - #2195

Merged
transphorm merged 2 commits into
devfrom
chore/fix-android-packages-crashing
Jul 3, 2026
Merged

fix Android StackOverflowError in MainApplication.getPackages#2195
transphorm merged 2 commits into
devfrom
chore/fix-android-packages-crashing

Conversation

@transphorm

@transphorm transphorm commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes a production StackOverflowError crash on Android: inside the anonymous DefaultReactNativeHost in MainApplication.kt, the unqualified packages reference resolved to the host's own Kotlin-synthetic getPackages() property instead of MainApplication's lazy packages property, so getPackages() called itself until the stack was exhausted.
  • The recursion only fires on legacy reactNativeHost code paths — never on New Architecture startup — which is why it escaped manual testing. Confirmed triggers in our dependency tree: Segment's trackDeepLinks (app opened via deep link with the analytics module live), RN core BlobProvider (external blob content:// resolution), and react-native-screens' debug-only overflow menu.
  • Adds the app's first Android JVM unit-test setup (JUnit + Robolectric) with a regression test that invokes the real getPackages(); it reproduces the exact crash signature on the old code and passes with the fix.

Changes

React Native app (Android native)

  • MainApplication.kt: qualify the reference as this@MainApplication.packages so getPackages() returns the app's package list instead of recursing.
  • app/build.gradle: add testOptions.unitTests.includeAndroidResources and JUnit/Robolectric/androidx-test dependencies.

SDK core

  • country-document-types.json: refresh bundled country/document data to match the live API (ID-card support now reported for most countries; Germany keyed as D<<). Fixes the failing country-data-sync.integration.test.ts in the workspace-test CI job. Same data as PR add doc-aware embed routing + sticky verification request #2194.

Tests

  • MainApplicationTest.kt: Robolectric regression test asserting getPackages() returns (with the custom packages present) instead of overflowing the stack. Verified red on the buggy code, green on the fix.
  • src/test/AndroidManifest.xml: mirrors the main manifest's merge overrides (ML Kit DEPENDENCIES, Firebase notification meta-data, application attributes) because the unit-test manifest merge does not inherit them.

Test Plan

  • pnpm lint && pnpm types passes
  • cd app/android && ./gradlew :app:testDebugUnitTest --tests "com.proofofpassportapp.MainApplicationTest" passes
  • Manual: open the app via a self:// / https deep link (cold and warm) — no crash
  • Manual: share/upload a blob from the app so another app resolves the blob URI — no crash

Native Consolidation Checklist

  • CONTRACTS.md reviewed - no unintended contract changes
  • Layer 1 bridge contract tests pass (cd app && pnpm jest:run / pnpm --filter @selfxyz/rn-sdk-test-app test)
  • Layer 3 builds pass (app iOS, RN test app iOS, RN test app Android)
  • Layer 4 manual smoke test signed off (if consolidation PR)
  • No new native business logic added (logic belongs in TypeScript)

🤖 Generated with Claude Code

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Android app package resolution to prevent recursion issues during startup.
    • Updated country-to-document-type mappings so most countries now default to a single document type.
  • Tests

    • Added a Robolectric regression test to ensure package loading returns the expected modules without infinite recursion.
  • Chores

    • Enhanced Android unit test setup to better support resource usage during tests.

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
self-webview-app Ready Ready Preview, Comment Jul 3, 2026 3:49pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Fixes MainApplication.getPackages() to use an explicit outer-scope packages reference, adds Android unit test support and a regression test, and updates country-to-document-type JSON mappings.

Changes

MainApplication fix and test coverage

Layer / File(s) Summary
Fix getPackages recursion
app/android/app/src/main/java/com/proofofpassportapp/MainApplication.kt
Qualifies the packages reference as this@MainApplication.packages in getPackages().
Add unit test setup and regression test
app/android/app/build.gradle, app/android/app/src/test/AndroidManifest.xml, app/android/app/src/test/java/com/proofofpassportapp/MainApplicationTest.kt
Enables Android resources for unit tests, adds JUnit/Robolectric/AndroidX test dependencies, supplies a test manifest for MainApplication, and adds a Robolectric test that reflects into getPackages() and asserts the expected package types are returned.

Country document type mappings

Layer / File(s) Summary
Update country mappings
packages/mobile-sdk-alpha/src/data/country-document-types.json
Changes many country entries from ["p", "i"] to ["p"], while preserving selected ["p", "i"] entries and the empty EGY mapping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing the Android StackOverflowError in MainApplication.getPackages.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/fix-android-packages-crashing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@transphorm transphorm changed the title fix crashing fix Android StackOverflowError in MainApplication.getPackages Jul 3, 2026
@transphorm
transphorm merged commit 5064b7f into dev Jul 3, 2026
56 checks passed
@transphorm
transphorm deleted the chore/fix-android-packages-crashing branch July 3, 2026 16:26
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.

1 participant