question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

0.62.1 Release APK: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

See original GitHub issue

Environment

System:
    OS: macOS 10.15.4
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 21.43 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
    Yarn: Not Found
    npm: 6.14.4 - ~/.nvm/versions/node/v10.16.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.8.4 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  Languages:
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: ^0.62.1 => 0.62.1 
  npmGlobalPackages:
    *react-native*: Not Found

Upgrading version

0.61.5->0.62.1

Description

I built my app for debug on Android, and everything works perfectly. However, when I build it for release, the build succeeds but upon launching the app it creates the following error:

java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
 	at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
 	at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(Unknown Source:2)
	at com.facebook.react.bridge.JSBundleLoader$1.loadScript(Unknown Source:10)
 	at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(Unknown Source:18)
	at com.facebook.react.r.a(Unknown Source:180)
 	at com.facebook.react.r.a(Unknown Source:0)
 	at com.facebook.react.r$e.run(Unknown Source:68)
	at java.lang.Thread.run(Thread.java:919)

I used this command to build my app:

cd android
./gradlew assembleRelease

Here is my build.gradle: https://gist.github.com/palkerecsenyi/1434ce9340c167b80847ea2dcee30528 app/build.gradle: https://gist.github.com/palkerecsenyi/6c09728996c4f982dc3bd11ad757c45b package.json: https://gist.github.com/palkerecsenyi/d42eb7f1af6a6d3a83db9e271e720aec index.js (not sure if that’s fully relevant): https://gist.github.com/palkerecsenyi/90274eadedb9ca9c8f4ebb0ec42f10ca

Reproducible demo

I’m not sure if this happens with all upgrades, and I’m not sure how to reproduce it. I know at least one other person has experienced this issue: https://github.com/facebook/react-native/issues/25348#issuecomment-606182604.

Thanks in advance!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:32
  • Comments:62 (1 by maintainers)

github_iconTop GitHub Comments

77reactions
palkerecsenyicommented, Apr 5, 2020

Update

I solved this issue by doing this before each build:

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

and then run

cd android
./gradlew assembleRelease

Adding the --assets-dest option to the command then gave a duplicate assets error when building, so I skipped that and it works perfectly.

Also, I tried experimenting with the version of hermes-engine, but that had no effect. This issue doesn’t seem to be anything to do with Hermes.

44reactions
evelantcommented, Oct 14, 2020

OK I’ve found a workaround for now. This probably isn’t a great solution since it doesn’t take into account build variants and whatnot but it works for a basic :app:assembleRelease.

I added the following to android/app/build.gradle

//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+
//Seems like there's a task ordering issue and the assets get computed before the bundle is copied
//This forces the copy task to run before merge resources
project.afterEvaluate {
        tasks.findAll { task ->
            task.name.startsWith('merge') && task.name.endsWith('Resources')
        }.each { t -> t.dependsOn "copyReleaseBundledJs" }
}

This forces gradle to run the “copy the js bundle to assets” task before the “merge assets into the apk” task. It seems that for whatever reason with gradle 4+ the task ordering can be wrong and the bundle gets moved to intermediate dir after gradle has already picked up all the assets so it never gets included in the APK.

Hopefully someone with more knowledge of gradle than I can chime in with a better solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to load script make sure you are either running a metro ...
unable to load script make sure you are either running a metro server or that your bundle "index.android.bundle" is packaged correctly for release...
Read more >
Unable to load script.Make sure you are either running a ...
Make sure you are either running a Metro server or that your bundle 'index.android.bundle' is packaged correctly for release. Screenshot. What ...
Read more >
React Native: Unable to load script: index. android.bundle
Unable to load script. Make sure you're either running a Metor service (run 'react-native start') or that your bundle 'index.android.bundle' ...
Read more >
0.62.1 Release APK_ Unable to load script. Make sure you're ...
Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. at com....
Read more >
unable to load script make sure you are either ... - YouTube
unable o load script in react native solution || unable o load script in react native || unable to load script in react...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found