React-native: unable to load scripts from assets 'index.android.bundle' on real device

Created on 18 Jul 2017  Â·  48Comments  Â·  Source: facebook/react-native

Is this a bug report?

NO

Environment

"native-base": "^2.2.1",
"react": "16.0.0-alpha.12",
"react-native": "0.46.3",
"react-native-meteor": "^1.1.0"
nodejs - 6.10.3

npm - 3.10.10

  • Target Platform: Android

operating system - ubuntu 16.04LTS

Expected result - output should be displayed on real device

Actal output -
unable to load script from assets index.android.bundle make sure your bundle is packaged correctly or your running a package server

steps taken to resolve the error -
adb reverse tcp:8081 tcp:8081

observations -
running react-native start or restarting machine gives output sometimes

Ran Commands Stale

Most helpful comment

This helped me resolve the problem in following steps.

  • If not than (in project directory) 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
  • react-native run-android

All 48 comments

I started experiencing this too. Works fine on ios simulator. Android simulator and physical device instantly crashes, regardless of adb reverse

then what should be done

+1

+1

+1

+1

It's driving me crazy now. any updates here?

+1

Have tried make bundle by hand with react-native bundle --entry-file index.android.js --bundle-output index.android.bundle and it still doesn't work.

It started working for me by running the project from android studio; 'adb reverse tcp:8081 tcp:8081', and 'react-native start' each separately.

I tried this https://stackoverflow.com/a/44476757/6785523 and now is working.

This link seems to be dead..
maybe you can post it again?

@snstrauss try copy / paste.

This helped me resolve the problem in following steps.

  • If not than (in project directory) 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
  • react-native run-android

@BhavanPatel After reload, get the error again.

Damn it worked!! Thanks @rod-stuchi
It should be fixed officially by developers thou.

@rod-stuchi, It loads the JS from Offline bundle so if we change anything in code we have to rerun ("react-native bundle") command. I tried placing script in package.json file but it won't work. On other hand this also disable debug mode.

will offical tend to slove this problem in next version ?

Every times when I edited app.js,I should run :

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

it is bad!

this never happened to me in windows.

Something is wrong, this is not normal. I am on Windows 10. This does not happen when testing on device, only when simulator for me.

I am having to run the above:

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
react-native run-android

Every time after making a change. Defeating hot reload. This only happens to me when using emulator. It builds to device fine.

Find another solution .Open MainApplication.java in the android/app/src/main/java/{packagename} directory ,delete the following code if exist

import com.facebook.react.BuildConfig;

BuildConfig.DEBUG should be true in debug mode ,while in com.facebook.react.BuildConfig it is always false.

@REBOOTERS That did it for me too after an intense git bisect. I believe an issue ought to be created for this since Android Studio complains that the import for BuildConfig is not present, and subsequently importing it causes nothing to work. Since it happens implicitly, its quite hard to trace too.

latest React-Native Cli fallow below Command in mac terminal run on android device
step1: If not than (in project directory) mkdir android/app/src/main/assets

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

step3: react-native run-android


@raktec thanks! this worked just fine for me!

In my case, adb path was not defined in environment variables and that's why it was not able to make the assets folder. I set the path and its working fine.

@akamittal Could you tell me how to define adb path in environment variables?

@lzmhhh123 If you have windows machine then follow these steps -

  1. Open Control Panel -> System -> Advanced System Settings -> Environment Variables
  2. Double Click on "Path"
  3. Click on New
  4. Add the platform tools path there. For me it was - C:\Users\akash\AppData\Local\Android\sdk\platform-tools
    Change "akash" with your Computer's user name.

Make sure you have adb installed before going through these steps.

@raktec

Do we need to execute this 3 lines of code every time we create an android release?

Its riddiculous !! I unistalled the app and reinstalled it worked all fine.
Previously also the same happened.. but no idea what is causing the issue sometimes.

Same issue with akamittal, setting the adb environment variable solves it.
AppData is hidden by default, enable view hidden files to locate.

@REBOOTERS thanks it worked for me .

So this fix does solve it, but I would like to understand why it is happening and do I need to run react-native bundle every time I build a new apk?

I get a red screen in my app with the following content:

Can't find variable: DOMParser

_connect_cb_wrapper
index.android.bundle?
platform=android&dev=true&minify=false:
61420:104

.
.
.

Anyone has any idea on it?

Install yarn from internet or choco.
Then normal 'react-native init name'.

(Install yarn before creation of project)
That's it.

If again it fails reply

Hi @sudhanvadp,

Same error even after installing yarn before creating project.

@SantoshSah
In the recent version of react-native they have fixed it. If you want complete freedom from this just uninstall node (For complete uninstallation Completely remove node refer this link) and reinstall node (LTS), react-native-cli then create your new project.

The latest react-native version worked fine for me when connecting to an Android device via USB, but the error still happens when connecting ADB to device via TCP/IP.

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to Contribute • What to Expect from Maintainers

Stil reproduce with 0.53.0

Have it in 0.53.3

same error in 0.53.3, test in physical device and virtual device both

well, what's work for me is just run a command in project root folder npm install .

If you're launching gradle via Android Studio try to disable _Offline Work_ (Preferences -> Build, Execution, Deployment -> Gradle). At least it fixed the issue for me.

updated from 0.53.0 to 0.54.3 and got this error

react-native v.0.54.3
I got the same error on android emulator. Solved with

  1. Make directory android/app/src/main/assets
  2. Execute command: react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

I tried to run 'adb reverse tcp:8081 tcp:8081' and my machine run. Because my service runs on port 8081

Sorry if I missed this already being mentioned but this can also be caused by setting org.gradle.configureondemand=true in your gradle.properties

@Override
public boolean getUseDeveloperSupport() {
return true;
}

worked for me as @REBOOTERS suggested but even before it was returning true it was working don't know what happened that I had to change it true.

Was this page helpful?
0 / 5 - 0 ratings