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.
Related
I'm trying to run my react native app on either an Android Studio emulator or my physical device. I've followed the instructions at https://reactnative.dev/docs/environment-setup under the React Native CLI Quickstart tab, and initialised the 'AwesomeProject' app from that page, but I'm finding the instructions unclear. For instance it says do the following on the command line: npx react-native start which starts up a process of some sort. Then it says to enter: npx react-native run-android, but the command line is blocked by the previous process. If I try the latter either in another command prompt or without first running the former command, I get an error Unrecognized command "run-android". I should say I have an emulator running from Android Studio before doing all this.
So failing getting it running via the react-native CLI, how do I get it running from within just Android Studio? I've never used Android Studio before, so I have no idea what the process is. Googling hasn't helped either. But as I said, I have managed to get an emulator installed and running.
Any help getting this going either via react-native CLI or from within Android Studio would be greatly appreciated.
edit: I've found how to run my app in Studio, but it pops up an 'Edit configuration' dialogue and says there's no Module selected. But in the module dropdown box there's nothing to select.
You can try following the below steps:
Make sure that you have 2 environment variables set in your system.
ADB variable which is set to the path of "platform-tools" in your system like below:
ANDROID_HOME variable set to SDK path, where android was installed.
Now execute below commands in command prompt and start you emulator or connect your phone which has development settings ON before this:
Open your command prompt in admin mode.
Delete node_modules folder
Execute: npm install
Execute: npm install -g react-native && npm install -g #react-native-community/cli
Execute: npx react-native init
Go to android folder in your react-native project and execute: npx gradlew clean
Come back to main folder and execute: adb reverse tcp:8083 tcp:8083. (You need to check the status of your connected devices by executing adb devices. It will show you the connected devices.)
You also need to make sure that your index.bundle is created. If not than you may create it by executing: npx react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --dev false --reset-cache --assets-dest android/app/src/main/res/
Finally execute: npx react-native run-android --port=8083
I encountered an issue today with react native. well every time when i face any issue i almost got a solution after digging into it or in internet for couple of hours but this issue is a real headache for me now.
Issue is that i am using few images in my assets folder and when i run react-native run-android and creates a bundle in my emulator everything works fine and smooth. I can see images. But when i create assembleRelease bundle to publish my app in app store and install that in my any device. no errors prompt but i can't be able to see the images. weird !
well i also found some solution but they're outdated and post were like 2018 and old.
Please help if you know or faced this error.
First, you should try this to get release build by this code
cd android && ./gradlew assembleRelease
If the above code doesn't work try this code with budling all assets and get the release
mkdir -p android/app/src/main/assets && rm -rf android/app/build && 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 && cd android && ./gradlew assembleRelease
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 :)
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
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 :)