Skip to content

fix(android): preserve HybridNitroNetworkInfo in R8 builds - #122

Open
maksymhcode-care wants to merge 1 commit into
patrickkabwe:mainfrom
maksymhcode-care:fix/android-r8-keep-hybrid-network-info
Open

fix(android): preserve HybridNitroNetworkInfo in R8 builds#122
maksymhcode-care wants to merge 1 commit into
patrickkabwe:mainfrom
maksymhcode-care:fix/android-r8-keep-hybrid-network-info

Conversation

@maksymhcode-care

@maksymhcode-care maksymhcode-care commented Aug 19, 2026

Copy link
Copy Markdown

Summary

  • mark the Android hybrid implementation with @DoNotStrip
  • preserve the class name and default constructor used by Nitro's generated JNI registration in minified release builds

Problem

NitroNetworkInfoOnLoad.cpp creates HybridNitroNetworkInfo through the hardcoded JNI descriptor Lcom/nitronetworkinfo/HybridNitroNetworkInfo;. Because the implementation had no shrinker annotation and no direct Java/Kotlin construction path, R8 could remove it from consumer release builds while retaining the generated spec.

Affected builds crash when the hybrid object is initialized:

NitroModulesProxy.createHybridObject(...):
java.lang.ClassNotFoundException: com.nitronetworkinfo.HybridNitroNetworkInfo

Debug builds are unaffected because they normally do not run R8.

Fix

Annotate the implementation with React Native's existing @DoNotStrip annotation. This matches the convention already used by the generated Nitro classes and adds no dependency or API change.

Verification

  • bun run typecheck
  • bun run build
  • built the Android example release with minifyEnabled true and x86_64 native architecture
  • verified R8 maps HybridNitroNetworkInfo to its original name
  • verified the default constructor is present in R8 seeds and the class is absent from usage.txt
  • installed the minified release APK on an x86_64 Android emulator and cold-started it successfully; the process remained alive and the crash buffer was empty

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of network information functionality by preventing required components from being removed during Android builds.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aad93076-b506-4d84-8793-20c8ae1f6249

📥 Commits

Reviewing files that changed from the base of the PR and between 07270eb and 3f09117.

📒 Files selected for processing (1)
  • android/src/main/java/com/nitronetworkinfo/HybridNitroNetworkInfo.kt

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Android module imports DoNotStrip and applies it to HybridNitroNetworkInfo.

Changes

Android class preservation

Layer / File(s) Summary
Annotate the hybrid class
android/src/main/java/com/nitronetworkinfo/HybridNitroNetworkInfo.kt
The file imports DoNotStrip and annotates HybridNitroNetworkInfo.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 3f091

This localized change preserves the hybrid class and constructor in minified Android releases, with the stated checks and release verification completed; no actionable merge-blocking risk remains beyond normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes preserving HybridNitroNetworkInfo during Android R8 builds, which is the main change.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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