Failed to load script from index.android.bundle 'assets

I am new to responding. I launched my own project on Ubuntu using the command "response-native run-android". And I got an error on the emulator 'Unable to load script from index.android.bundle' assets. Make sure your package is packaged correctly or you are using the package server.

+9
source share
15 answers

I also got this, and I solved it using the following commands in the 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 
+20
source

Using npm version 4.3.0 reaction-native-kli version 2.01 reactive version 0.49.5

In the project directory

  • mkdir android/app/src/main/assets
  • 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
  • react-native run-android

The file name has changed from index.android.js to index.js

+12
source

In my case (embedding React Native as a new Activity in an existing Android Code database) the problem was that Android Studio automatically imported the wrong BuildConfig .

Wrong: import com.facebook.react.BuildConfig;

Right: import com.mywebdomain.myapp.BuildConfig;

This applies to where you place this block of code:

 mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModulePath("index") .addPackage(new MainReactPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); 
+7
source

This helped me solve the problem in the following steps.

  • If not (in the 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

+2
source

Ubuntu

The first time I created a new application with react-native init project-name . I got the same error. therefore, I am taking the following steps to solve this problem in my case.

  1. First run sudo chown user-name-of-pc/dev/kvm in my case.
  2. When debugging from an Android phone, select " Use USB to Transfer photos (PTP) ."
  3. Create the folder resources in "project-name / android / app / src / main".
  4. make sure index.js in the root directory of your project, and then run the command below from the console after the cd project-name directory.

own package --platform android --dev false - input file index.js - output android / app / src / main / assets / index.android.bundle --assets-dest android / app / src / main / RES

or for index.android.js then

native package - platform android - dev false - input file index.android.js - output / output android / app / src / main / assets / index.android.bundle --assets-dest android / app / SRC / main / RES

  1. ./studio.sh command ./studio.sh at ./studio.sh android-studio/bin . Android Studio opens.
  2. run react-native run-android command.
+2
source

There seems to be a problem in the latest version of React Native (0.46). Using the previous version seems to solve the react-native init name --version react-native@0.45.1 problem and removes the error when react-native run-android starts.

Edit: Now it is fixed in version 0.46.1.

+1
source

For this error:

Could not load script from index.android.bundle.

1) Check the assets folder:

 mkdir android\app\src\main\assets 

If the folder is unavailable, manually create a folder named "assets". and execute the curl command in the terminal.

2). Curl Command:

 curl "http://localhost:8081/index.android.bundle?platform=android" -o"android/app/src/main/assets/index.android.bundle" 

It will automatically create the index.android.bundle file in the resource folder and fix the problem.

3) Then:

  react-native run-android 
+1
source

In my case, the problem was in this line in the React Activity file:

 mReactInstanceManager = ReactInstanceManager.builder() ... .setUseDeveloperSupport(BuildConfig.DEBUG) ... 

BuildConfig.DEBUG should be set to true, whereas in my case it was false

+1
source

For Windows users only:

  1. Copy the ADB location path and set to PATH in your system variable,
  2. Open the project structure and delete the node module folder.
  3. Edit your package.JSON project. package.JSON file change response-native version "react-native": "0.55.2" and babel "babel-preset-react-native": "4" , then run npm install
  4. Restart cmd and js server and run your own react-native run-android project
+1
source

I was stuck in the same problem for several hours, and this solved my problem like this: create the "assets" folder in the main directory of the project, as well as in "newreactproject \ android \ app \ src \ main". Then put this script in package.json "android-android": "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 && react-native run-android"
like:

 "name": "newreactproject", "version": "0.0.1", "private": true, "scripts": { "android-android": "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 && react-native run-android", "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" } 
+1
source

I found the solution suggested in the thread at https://github.com/facebook/react-native/issues/15388

To install the application on the phone, manually configure the host and port of the debug server.

Step by step to extract and run CRNA on Android

In terminal:

  • create-react-native-app myApp
  • cd myApp
  • yarn run eject (I used the default option "regular React Native project")
  • react-native run-android

(Now the application must be compiled and installed on the phone)

On the phone:

  1. Launch the application (expect to see a red error screen - click the "Reject" button in the lower left)
  2. Shake your phone and select Dev Settings
  3. Select the host and port of the debug server for the device and set the value to 192.168.xx: 8081 (make it your actual LAN interface).
  4. Restart the application on the phone and you will see a green bar at the top "Download from 192.168.xx: 8081 ..."
  5. You should also see the " index.js " action in the Metro Bundler (open when react-native run-android starts)
  6. After the package is completed, the application must be running on your Android device!

Live Reload (when changing source files) also works - just shake your phone and click on โ€œEnable Live Reloadโ€

You can start the project from Android Studio, but first you need to run the Metro Bundler with the react-native start command in the root of the CRNA project.

0
source

I also got this error. But adb reverse worked for me

0
source

I am using Ubuntu 18.04 LTS, reactive: 0.55.2. In my case, here are a few solutions to the problem.

  1. in the terminal, before running npm, run android like npm start. you may see an error ERROR Metro Bundler cannot listen on port 8081. this is because there may be a process that is already running

    Solution- type sudo lsof -i :8081

    you will see a conclusion similar to this

    ** SIZE OF THE COMMAND PID USER DEVICE. DEVICE TYPE FD.

      node 5670 tasif 17u IPv6 80997 0t0 TCP *:tproxy (LISTEN)** 

    type kill -9 (PID number) then run npm android .

  2. if this still does not work, type npm start again. You can see this error

    E RROR ENOSPC: no space left on device, watch'....../......./.....'

    decision:

    $ sudo sysctl fs.inotify.max_user_watches=524288

    $ sudo sysctl -p

    then type npm run android .

    follow this link to see various solutions and more detailed information https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

  3. remove the emulator and reassemble it. kill the last terminal, then assemble the emulator and start over.

0
source

For Android 9+ emulator / device

See this GitHub comment

0
source

When you install NodeJS using the choco command ( choco install -y nodejs.install python2 jdk8 ), it will install the latest version of the node, 12.12.0, at the time of writing this answer. You should downgrade it to 10.16.3 and run the command act-native run-android , and it should work fine

0
source

Source: https://habr.com/ru/post/1269018/


All Articles