0

I upgraded my React Native project from 0.63.3 to 0.66.4 with the help of this resource https://react-native-community.github.io/upgrade-helper/?from=0.63.3&to=0.66.4 (followed every instruction in it).

But after generating the apk and I see the below error during the launch ->

01-27 19:12:46.364  9223  9895 E AndroidRuntime: 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.
01-27 19:12:46.364  9223  9895 E AndroidRuntime:    at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
01-27 19:12:46.364  9223  9895 E AndroidRuntime:    at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:2)
01-27 19:12:46.364  9223  9895 E AndroidRuntime:    at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:1)
01-27 19:12:46.364  9223  9895 E AndroidRuntime:    at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:3)
01-27 19:12:46.364  9223  9895 E AndroidRuntime:    at com.facebook.react.o.s(ReactInstanceManager.java:39)
01-27 19:12:46.364  9223  9895 E AndroidRuntime:    at com.facebook.react.o.c(ReactInstanceManager.java:1)
01-27 19:12:46.364  9223  9895 E AndroidRuntime:    at com.facebook.react.o$f.run(ReactInstanceManager.java:12)

My index.android.bundle is getting generated in the correct path And I tried every possible solution below to resolve this error, but nothing seems to resolve the above error:

  • $ mkdir android/app/src/main/assets

    $ react-native bundle --platform android --dev false --entry-file index.android.js -- bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

  • In Project build.gradle =>

    project.ext.react= [

     bundleInDebug: true,

     bundleInRelease: true ]

  • In androidManifest.xml =>

    android:usesCleartextTraffic="true"

    tools:ignore="GoogleAppIndexingWarning

  • In Project build.gradle =>

    project.ext.react= [

    entryFile: "index.js",

    bundleAssetName: "index.android.bundle",

    devDisabledInAppDev: true,

    devDisabledInRelease: true ]

  • https://stackoverflow.com/a/49143330/18210851

Please suggest some solution.

shweta
  • 31
  • 4

1 Answers1

0

Before doing the first step i.e., mkdir android/app/src/main/assets, you have to run the metro server using the npm start command. The below link has all the steps required to create an offline APk in debug mode.I can see that the first step is missing.

https://stackoverflow.com/a/37965603/8988448

Gavara.Suneel
  • 458
  • 2
  • 14
  • I am running first npm start only. – shweta Feb 02 '23 at 16:29
  • Ok. The problem here is pretty much clear. If you see the description of the error "Make sure you're either running Metro (run 'npx react-native start')", it simply states that still, your app is looking to make a call to the metro server to get the javascript( debug apk and release apk should not do this). Could you try to clear the gradle cache and metro cache before running the above steps using below commands? command 1: cd android && ./gradlew clean 2: npm start --reset-cache. – Gavara.Suneel Feb 02 '23 at 16:41
  • 1
    Have done it all. build is working fine on local machine. The release apk on bamboo throws this error on app launch – shweta Feb 02 '23 at 16:58
  • If it is the release build, i would suggest you the check this link. https://github.com/react-native-community/upgrade-support/issues/38#issuecomment-1209353339 – Gavara.Suneel Feb 02 '23 at 18:02
  • @Swetha., any luck with the above comment? I suspect the issue is with the release build – Gavara.Suneel Feb 03 '23 at 07:16
  • Hi, Still no luck. No workaround is helping. The issue persists with release build. – shweta Feb 03 '23 at 07:35
  • Ok. I thought the above link would solve the issue. But I have a question here. Are you still running npm start as the first step? I think this step would be needed only if you are building debug apk. But as you are building release one, you should not run that step I believe. This link mentions 4 steps that needs to be followed. https://github.com/react-native-community/upgrade-support/issues/38#issuecomment-1209353339. – Gavara.Suneel Feb 03 '23 at 11:53