Currently I have implemented reactnative to existing native app but its directly crashing when i start it from android studio. windows doesnt turns red as usual.
Process: com.., PID: 15608
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)
The problem that you are facing is that a react native project creates a bundle to load the script for the app which you have not created it so your android app is loading nothing when running the react-native run-android command.
Do this in your project root directory:
1- Run this command mkdir android\app\src\main\assets
2- After this command, run this 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
Step 2 command execution might take time (have patience)
3- then run react-native run-android command
More info at here and here
Related
I created the app by working on the following tasks for the launch of the Android app.
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
After that, I tried to build the app again in development mode (react-native run-android), but the app continues to be built in release mode. How do you build it development mode like before?
react-native run-android
When I do this react-native run-android, Metro Bundle does not run and just build the release app on my device.
I want the Metro Bundle to be turned on and built in development mode when I execute this.
I had the same problem, it was fixed by deleting the line:
import com.facebook.react.BuildConfig;
from the MainApplication.java
Below can clear your thoughts about the metro server and development mode
When you are in development mode and need to debug the application
live by changing the content of the code the you should always do:
react-native run-android, it will always run the metro server and
you have the feature to live reload the application whenever the code
changes. Note: This will work for both the emulator and phones
connected to your pc through cables or by server.
Now, in case you want to build an apk and wanted to test on a real
device which enables you to discard the consoles and for the further
testing the application before making it live then you should always
run the below command
Bundle first all the files, by going inside your project
structure
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/
Now, create a bundle apk by going inside the android folder and run the below command./gradlew assembleDebug
Note : it will create the apk in you build folder inside this
directory project_name\android\app\build\outputs\apk\debug
I hope this helps....Thanks :)
I created AwesomeProject and run react-native run-android in root directly of my project, message in android simulator is as follows:
Unable to load script.Make sure you are either running a Metro server or that your bundle 'index.android.bundle' is packaged correctly for release.
To fix this err i try to run :
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/
but it didn't work.message in android simulator
You have to start the bundler first, run
npm start
or
react-native start
in the root of your project.
I'am just starting with react native using Android emulator on windows. When I follow the react native getting started tutorial and run the app I see 'unable to load script from assets index.android.bundle' error and fixed it by following these steps as explained here :
(in project directory) mkdir android/app/src/main/assets react-native
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
This worked good - App.js renders ok, but I am now unable to see any changes made to the code in the emulator (I have tried running npm-start and react-native run-android but no luck). When I hit reload button in the emulator (RR) I see this error : error
I have also tried resetting cache(react-native start --reset-cache) and no luck.
How could I get my changes refreshed in the app please and fix this error? Thanks :)
I have made many changes in my js code, when I run in debug mode I'm able to see all the changes but when I run the app in release mode or generate a release apk, the changes that were made and visible in debug mode are not visible.
What I have already tried?
react-native run-android --variant=release
Deleted the builds folder and android.bundle.js in assets
Run the below command before you run release variant in the project directory.
So command sequence will be first execute
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/
This may take little time to finsh.
Then execute your run command:
react-native run-android --variant=release
I am running $react-native run-android. it is working properly, also, I am able to see the changes on android emulator. I have created 3 components and also tested it on android device.
But now, suddenly, it is asking me unable to load script from assets 'index.android.bundle' Also, I have reverted the changes and started but still I am seeing this error.
After serching on internet, I performed,
1. npm start
2. react-native start
3. adb kill-server and adb start-server
but all in vein.
Last, I found and performed below commands,
$ 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
I am able to resolve above error with above commands, but now, when I am changing App.js file, it is not getting reflected on emulator. please help.
My steps performed: http://sachin4java.blogspot.in/2017/12/unable-to-load-scripts-from-assets.html
I have tried many things as found on internet, but no one worked.
I removed installed node, NPM and nodejs
I installed it again with : http://sachin4java.blogspot.in/2017/12/react-native-setup-in-ubuntu-16.html
Then I installed in new version in Android studio AVD image named 'Nexus_5X_API_26(AVD)'.
Now, I am able to see the code changes reflecting and red error screen gone.