Mobile

React Native Android release APK crashes on cold start only when R8 minification is enabled — index.android.bundle missing at runtime

Environment

Environment

React Native 0.70 app, Android Gradle Plugin 7.2, Java 11, CI builds via GitLab Runner producing release APKs with minifyEnabled=true and shrinkResources=true; debug APKs (no minify) run OK on Pixel 5 (Android 13) and Samsung S22 (Android 12).

Symptoms

Symptoms

Release APK crashes immediately on cold start with an uninformative crash dialog on device; Android system log (adb logcat) shows app process killed after startup with Java runtime exceptions obfuscated. Users report 'app won't open' — no JS bundle loads. Reproducible locally when building with minify enabled.

Observations

Observations

  1. Unzipping the release APK shows assets/index.android.bundle is missing in the APK when minify/shrinkResources are enabled; debug APK contains the bundle. 2) Building with minifyEnabled=true but shrinkResources=false sometimes contains the bundle but still crashes. 3) Disabling R8 (minifyEnabled=false) makes release APK work. 4) ProGuard/R8 rules were default plus some custom -keep for com.example.* classes, but no rules relating to React Native packaging tasks. 5) CI logs show 'mergeAssets' and 'aapt' steps completed without errors.
Already attempted

Already attempted

Tried disabling shrinkResources and minify separately, added generic -keep rules for React Native packages (com.facebook.react.**), ensured bundle generation gradle task runs, verified gradle's react.gradle is applied. Rebuilt with --no-daemon and cleaned caches; results inconsistent until minifyDisabled.

Question

Question

Why is the JS bundle not packaged in the release APK when R8/minification/shrinkResources are enabled, and how can I keep code shrinking active while ensuring a valid release APK with the bundle included and no startup crash?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4h ago• Trouble ID

Most likely causes

Gradle resource shrinking or packaging step (shrinkResources/minify) strips the index.android.bundle asset because it's not referenced in R files, causing the bundle to be absent in the release APK 65%
R8/ProGuard optimizations remove classes or methods responsible for initializing the React Native bridge or locating assets at runtime, causing a crash even when the bundle exists 40%
Bundle generation task is being skipped in CI for release/minified builds because of an environment difference or modified react.gradle hook (e.g., NODE_BINARY path or gradle property not set), so no bundle is produced to include 30%

Summary

The most consistent finding is that resource shrinking or an R8 optimization/packaging step is removing the JS asset from the APK or altering asset packaging so the app can't find index.android.bundle at runtime. Possible causes include a misconfigured Gradle sourceSets or react.gradle hook being skipped in minified releases, or shrinkResources erroneously pruning the asset because it's not referenced in native resource tables. Another possible (but less likely) cause: R8 obfuscation removes classes that run bundle-loading code, preventing the bundle task from running or preventing runtime lookup, which explains why bundle may appear present but the loader fails. CI differences (e.g., environment variable that controls bundle generation) could also be involved.

Suggested Fixes

Diagnostic step 1
Unzip the problematic release APK and verify presence and path of assets/index.android.bundle. If missing, the problem is packaging — focus on Gradle tasks.
Diagnostic step 2
Temporarily set minifyEnabled=true and shrinkResources=false to isolate whether resource shrinking removes the asset. If bundle present with shrinkResources off but missing when enabled, add keep rules to prevent the asset from being stripped or disable resource shrinking.
Diagnostic step 3
Ensure the RN gradle bundle task runs in release: run ./gradlew assembleRelease --info and look for ':app:bundleReleaseJsAndAssets' execution and its output. If the task is skipped, check react.gradle inclusion and NODE_BINARY environment variable in CI.

Continue troubleshooting

Matched from the title, description and tags