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 issueEnvironment
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:
- Created 3 years ago
- Reactions:32
- Comments:62 (1 by maintainers)
Top GitHub Comments
Update
I solved this issue by doing this before each build:
and then run
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.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
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.