react-native: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server. App crash in release build only
- Review the documentation: https://facebook.github.io/react-native
- Search for existing issues: https://github.com/facebook/react-native/issues
- Use the latest React Native release: https://github.com/facebook/react-native/releases
Environment
Done in 2.05s. - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.7.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
Android SDK:
Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.2, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.3, 28.0.0, 28.0.2, 28.0.3
API Levels: 22, 23, 24, 25, 26, 27, 28
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
react: 16.5.0 => 16.5.0
react-native: 0.57.1 => 0.57.1
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
Description
I get the error below on release builds. I don’t see the issue in my dev environment i.e. react-native run-android
. I installed the apk on my Pixle 2 XL - Android Pi and the app immediately crashes. I got the error below from my Firebase console (Crashlytics)
Fatal Exception: java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(CatalystInstanceImpl.java)
at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:32)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:243)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1114)
at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:913)
at java.lang.Thread.run(Thread.java:764)
Reproducible Demo
Let us know how to reproduce the issue. Include a code sample, share a project, or share an app that reproduces the issue using https://snack.expo.io/. Please follow the guidelines for providing a MCVE: https://stackoverflow.com/help/mcve
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 23 (4 by maintainers)
For me this combination worked using
"react-native": "0.59.4"
gradle-wrapper.properties
adddistributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
build.gradle
useclasspath 'com.android.tools.build:gradle:3.3.0'
build.gradle
I have:right above
apply from: "../../node_modules/react-native/react.gradle"
For some reason I had
import com.facebook.react.BuildConfig;
in my MainAplication file (I guess due to some smart ass auto import fixing feature of IntelliJ), and thereforeBuildConfig.DEBUG
was set to false. Because of this:React Native was always trying to load index.android.bundle from the app pacakge, not from the dev server. Removing the
import com.facebook.react.BuildConfig
line fixed the issue for me 🎆 🍺 👍It turned out to be a problem of
gradle plugin
Use 3.3.* instead of 3.4.* works for me:
I still use gradle 5.4.1. This does not cause the problem, though.
I have the same problem when running an app in emulator, downgraded gradle to 3.1.4 but it didn’t work.
My packaging server is running on port 8081 (via
react-native start
).Isn’t react-native supposed to run the command to build the bundle file automatically? I can’t run it manually on every change, it’s insane (in particular because the command runs extremely slow).
In Android Studio the Build Variant option is set to debug for all modules.
Update:
I found a way to automatically run the bundle script: add this to your app/build.grandle:
Apparently the
bundleInDebug: true
option tells React Native to build bundle files in debug (development) builds.But this is still not a solution… ideally the app should connect to the packager server running on localhost, but for at least it doesn’t do that, sadly I haven’t figured out why 😞
Update 2:
Also: https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted/50834600#50834600
This worked for me: https://github.com/facebook/react-native/issues/18357#issuecomment-460015070
In
app/build.gradle
Add:
Above the line:
I am closing this issue because it does not contain the necessary environment info, and there has been no followup in a while.
If you found this thread after encountering the same issue in the latest release, please feel free to create a new issue with up-to-date information by clicking here.
I have same issue when upgrade into latest version:
classpath 'com.android.tools.build:gradle:3.2.1'
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
-build:
cd android & ./gradlew assembleDevRelease
-> I have config dev env in gradle. -env:This issue only have in release build. Debug mode is not.
@vafada and @sinhpn92 thanks for pointing out the gradle version I downgraded to
com.android.tools.build:gradle:3.1.4
and it started working.Thanks
Look at this: https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff
For my project using react-native
0.57.0
, it is because I upgraded my Android gradle plugin from3.1.4
to3.4.1
to enable androidx support libraries. And the new gradle plugin uses a different intermidiate directory for assets, but thereact.gradle
copies the js bundle into the old directory.So it builds with js bundle in assets after I changed the
react.gradle
as below.you can replace the new asset dir with the one your gradle plugin uses if it is not the same(for me it is
"$buildDir/intermediates/merged_assets/${variant.name}/out"
). You can find it as following.a.a
to yourasset
directory../gradlew assembleDebug
a.a
in./app/build/intermidiates
folder. The folder containsa.a
is the intermidiate directory for asset files, change the destination dir inreact.gradle
to it.I had this issue only on Mac OS and only while trying to build for Android. It started to happen after my update from RN 0.57 to 0.59.
To understand what is going on I started a new RN project and compared differences with my project. I noticed that there is a new folder in the new project - android/app/src/debug. And there is only one file in this folder - AndroidManifest.xml with the following contents:
After adding this file to my old project Metro Bundler started working for Android as expected.
This worked for me 😃
@vinnyhoward solution works for me as well. This saved the few remaining hairs on my head. No need to change distributionUrl though, gradle-5.1.1-all.zip worked fine.
@vinnyhoward answer works for me.