Home > Mobile >  index.android.bundle missing in APK after upgrading to RN 0.68
index.android.bundle missing in APK after upgrading to RN 0.68

Time:04-15

After upgrading our RN app to RN 0.68, we are getting errors with the release build:

FATAL EXCEPTION: create_react_context
Process: com.app, PID: 15057
java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

The app works fine in development, and was fine before upgrading. It is using Hermes, but not using the new Fabric architecture.

When building the APK and then looking into its content, we can see that the bundle is not copied. But it is correctly built in the intermediate artifacts:

$ ./gradlew assembleRelease
…
BUILD SUCCESSFUL in 45s
1050 actionable tasks: 14 executed, 1036 up-to-date

$ unzip -l app/build/outputs/apk/release/app-arm64-v8a-release.apk | grep bundle
<nothing>

$ ls -l app/build/outputs/apk/release/app-arm64-v8a-release.apk
-rw-r--r--  1 renchap  staff  15618010 Apr 12 21:03 app/build/outputs/apk/release/app-arm64-v8a-release.apk

$ find . -name "index.android.bundle"
./app/build/generated/assets/react/release/index.android.bundle
./app/build/intermediates/merged_assets/release/out/index.android.bundle
./app/build/intermediates/merged_assets/release/mergeReleaseAssets/out/index.android.bundle
./app/build/intermediates/assets/release/index.android.bundle

$ ls -lh ./app/build/intermediates/assets/release/index.android.bundle
-rw-r--r--  1 renchap  staff    11M Apr 12 19:48 ./app/build/intermediates/assets/release/index.android.bundle

I am suspecting that there is a missing build step and it is not copied to the final directory, but I am not familiar enough with Gradle or RN's build process to check this.

Do you have any idea of what can cause this, or where to look at to troubleshoot this?

CodePudding user response:

Found it after comparing the build files with a brand new RN app!

I had

classpath("com.android.tools.build:gradle:7.1.2")

in android/build.gradle

But with RN 0.68, you need to depend exactly on version 7.0.4, otherwise the JS bundle is not copied into the final APK.

The release APK is now working after switching to

classpath("com.android.tools.build:gradle:7.0.4")
  • Related