Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #22076

Closed
naody opened this issue Nov 2, 2018 · 19 comments

Comments

Projects
None yet
@naody
Copy link

commented Nov 2, 2018

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

@react-native-bot

This comment has been minimized.

Copy link
Collaborator

commented Nov 2, 2018

Can you run react-native info and edit your issue to include these results under the Environment section?

If you believe this information is irrelevant to the reported issue, you may write [skip envinfo] under Environment to let us know.

@bartolkaruza

This comment has been minimized.

Copy link
Collaborator

commented Nov 2, 2018

What command did you use to make the release build? Can you post an (anonimized) copy of your android/app/build.gradle ?

The (default) debug build retrieves the js bundle from the packager at runtime. A release build needs a local version of the bundle in the binary. Your error indicates that this local bundle is not present in the APK.

This can be caused by a misconfigured app/build.gradle, such as pointing to the wrong bundle name or not packaging during the release process all.

@vafada

This comment has been minimized.

Copy link

commented Nov 5, 2018

@naody

Did you happen to upgrade gradle version?

I got the same issue when I upgraded:

classpath 'com.android.tools.build:gradle:3.2.1'

from

classpath 'com.android.tools.build:gradle:3.1.4'

and

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

from

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

@sinhpn92

This comment has been minimized.

Copy link

commented Nov 5, 2018

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:

Environment:
  OS: macOS 10.14
  Node: 9.8.0
  Yarn: Not Found
  npm: 6.4.1
  Watchman: 4.9.0
  Xcode: Xcode 10.0 Build version 10A255
  Android Studio: 3.2 AI-181.5540.7.32.5056338

Packages: (wanted => installed)
  react: ^16.0.0 => 16.4.1
  react-native: ^0.55.4 => 0.55.4

This issue only have in release build. Debug mode is not.

@naody

This comment has been minimized.

Copy link
Author

commented Nov 5, 2018

@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

@sryze

This comment has been minimized.

Copy link
Contributor

commented Nov 10, 2018

I have the same problem when running an app in emulator, downgraded gradle to 3.1.4 but it didn't work.

2018-11-10 19:28:34.949 16195-16214/com.upnest.agent E/AndroidRuntime: FATAL EXCEPTION: Thread-4
    Process: com.upnest.agent, PID: 16195
    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(Native Method)
        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)

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).

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
      Memory: 119.93 MB / 16.00 GB
      Shell: 5.6.2 - /usr/local/bin/zsh
    Binaries:
      Node: 11.0.0 - /usr/local/bin/node
      Yarn: 1.12.1 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.6.1 => 16.6.1
      react-native: 0.57.2 => 0.57.2
    npmGlobalPackages:
      create-react-native-app: 1.0.0
      react-native-cli: 2.0.1

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:

project.ext.react = [
    entryFile: "index.js",
    bundleAssetName: "index.android.bundle",
    bundleInDebug: true,
    bundleInRelease: true
]

...

// This has to go AFTER you set project.ext.react properties:
apply from: "../../node_modules/react-native/react.gradle"

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

@sryze

This comment has been minimized.

Copy link
Contributor

commented Nov 10, 2018

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 therefore BuildConfig.DEBUG was set to false. Because of this:

    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

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 🎆 🍺 👍

@react-native-bot

This comment has been minimized.

Copy link
Collaborator

commented Nov 19, 2018

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.

@IgorBelyayev

This comment has been minimized.

Copy link

commented Feb 13, 2019

This worked for me:
#18357 (comment)

In app/build.gradle

Add:

project.ext.react = [
    entryFile: "index.js",
    jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/mergeReleaseAssets/out"
]

Above the line:

apply from: "../../node_modules/react-native/react.gradle"
@deserthurricane

This comment has been minimized.

Copy link

commented Apr 18, 2019

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:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>

After adding this file to my old project Metro Bundler started working for Android as expected.

@vinnyhoward

This comment has been minimized.

Copy link

commented Apr 19, 2019

For me this combination worked using "react-native": "0.59.4"

  • In gradle-wrapper.properties add distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
  • in root build.gradle use classpath 'com.android.tools.build:gradle:3.3.0'
  • in app build.gradle I have:
project.ext.react = [
        entryFile: "index.js",
        bundleAssetName: "index.android.bundle",
        bundleInAlpha: true,
        bundleInBeta: true
]

right above apply from: "../../node_modules/react-native/react.gradle"

@luizdotpro

This comment has been minimized.

Copy link

commented Apr 25, 2019

Thank you @vinnyhoward ! That worked perfectly for me.

@ajbarry

This comment has been minimized.

Copy link

commented Apr 26, 2019

Seriously @vinnyhoward Thank you! My release apk has been broken for days and I have been trying everything to get it to include the bundle. Android Studio "strongly recommends" upgrading gradle to 5.1.1 and it looks like that was my problem after all. Cheers! 🍻

@robertying

This comment has been minimized.

Copy link

commented Apr 28, 2019

It turned out to be a problem of gradle plugin

Use 3.3.* instead of 3.4.* works for me:

classpath 'com.android.tools.build:gradle:3.3.2'

I still use gradle 5.4.1. This does not cause the problem, though.

@MuhammadUsman786786

This comment has been minimized.

Copy link

commented May 10, 2019

@vinnyhoward answer works for me.

@buskerone

This comment has been minimized.

Copy link

commented May 17, 2019

@vinnyhoward solution works for me! Thanks

@cbsom

This comment has been minimized.

Copy link

commented May 20, 2019

@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.

@MakhouT

This comment has been minimized.

Copy link

commented May 22, 2019

@vinnyhoward That worked for me too.
As @cbsom said, no need to change the distributionUrl
Took me a day to find this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.