Mobile

Release APK contains index.android.bundle but app crashes on startup with obfuscated NoSuchMethodError after enabling R8 — ProGuard keep rules may be incomplete

Environment

Environment

React Native 0.68 app, Android release build with minifyEnabled=true and R8 active, devices tested: Moto G Power (Android 11) and Pixel 6 (Android 13); CI uses Gradle 7.1, Java 11.

Symptoms

Symptoms

Release builds with R8 enabled crash on app start for some users; logs (deobfuscated where possible) indicate NoSuchMethodError/NoClassDefFoundError originating from ReactNative's native modules initialization. Unobfuscated builds or builds with minification disabled run fine.

Observations

Observations

  1. index.android.bundle is present inside the APK assets. 2) Deobfuscated stack trace (after uploading mapping file) shows missing native method wrappers and React Native bridge classes. 3) Adding broad -keep rules for com.facebook.react.* resolves crash in one test build, but also prevents code shrinking to desired size. 4) The problematic code paths are in classes loaded via reflection or JNI registration patterns.
Already attempted

Already attempted

Added targeted -keep class com.facebook.react.** and -keepclassmembers for native-registered methods; rebuilt and validated on devices. Measured APK size and verified app stable in these builds. Tried to narrow keep rules but crash reappeared until a group of bridge classes were kept intact.

Question

Question

Which R8/ProGuard keep rules are safe and minimal to prevent React Native bridge classes from being stripped while allowing most code shrinking? Is there an established minimal rule set to avoid runtime NoSuchMethodError on release builds?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 3h ago• Trouble ID

Most likely causes

R8/ProGuard optimizations strip or rename classes and methods used by React Native's reflection or JNI registration (bridge/native modules), causing runtime NoSuchMethodError 95%
Third-party native modules do not bundle correct JNI registration metadata so R8 erroneously class-shrinks them 40%
Incomplete mapping upload process in CI leading to difficulty deobfuscating errors and misdiagnosing the keep rules needed 20%

Summary

This report differs from the previous RN bundling issue: here the bundle exists but R8 has removed or renamed classes/methods that are referenced via reflection or JNI, which leads to NoSuchMethod/NoClass errors. The fix is targeted ProGuard rules that preserve classes and methods used by React Native's reflection/JNI registration style. The evidence that broad keep rules eliminate the crash supports this. A balanced set of keep rules is required rather than disabling minification entirely.

Suggested Fixes

Diagnostic step 1
Add known community-recommended minimal ProGuard keep rules for React Native (keep com.facebook.react.** and JNI/reflective method signatures) and rebuild. Test on representative devices and verify startup works.
Diagnostic step 2
Audit third-party native modules for reflective/JNI entry points and add keep rules for their package namespaces (keep class <module-package>.** { *; }).
Diagnostic step 3
Use R8's printmapping and shrinking reports to identify which classes/methods were removed and iteratively relax keep rules to find minimal set that prevents crashes while allowing shrinkage.

Continue troubleshooting

Matched from the title, description and tags