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 - adb

I created a new project with react-native init .
I am using react-native with the following:"react": "16.13.1","react-native": "0.63.2".
When i am trying to run the app with react-native run-android command it shows build successful in the terminal but nothing appears in my metro bundler(I am attaching the image of it) and my emulator shows the 'Unable to load script' issue.
Unable to load script
If I press 'R' to reload the app in node(bundler) it says there is no device attached to it but my emulator is running. I encountered the same problem with personal device also.
metro bundler not running
I also tried by creating the assets folder in android/app/src/main/assets and run the below 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.
With this only once the app gets displayed on the emulator and when I make changes in the App.js file and save it there is no change in the emulator.
If I reload the error "Could not connect to the development server" pops up.
could not connect to development server
Even tried the adb reverse and changing 'dev' options to local host and port 8081, but it was not useful. (If there is any specific path where I should try the above steps please mention).
What is that I have done wrong?
Can anyone help please.
P.S.: I am using a windows 10 machine.
Thank you.

"react-native": "0.64.1",
I used other solution but I've resolved this issue in other way.
I resolved it by changing bundleInDebug: true, in project.ext.react in android > app > build.gradle.
project.ext.react = [
bundleInDebug: true,
enableHermes: ***,
]

I am also facing this issue and I try the below method to fix the issue.
for start the npm server use npx react-native start
in another tab npx react-native run-android for run the application.

Many devs have different environment setup and this complicates the solution.
I'm working on Windows with WSL2. Initially, I followed this react-native setup guide with no problems but later encountered this error, not sure why.
After many hours of searching and trying most of the answers from this duplicate question, among others, I had no luck.
Eventually, all I had to do from WSL2 was pass the host option to react-native start in order to connect to the adb server running on Windows.
yarn start --host 127.0.0.1
# or npx react-native start --host 127.0.0.1

I got this issue, I solved with close the app form emulator or if you use android or iphone device you can uninstall the app.
start again npm server use npx react-native start
reinstall app use npx react-native run-android

Related

The development client (com.reactnative02) for this project is not installed. Please build and install the client on the device first

I am getting the above error when previewing the react app on an android studio simulator. Please help. Here is the error:
"CommandError: The development client (com.reactnative02) for this
project is not installed. Please build and install the client on the
device first."
I was facing the same issue and below commands helped me to resolve it. Hope works for you as well.
Firstly close your Metro Bundler and emulator, then try:
expo run:android
If it doesn't help go with:
npx react-native run-android
Uninstall the application via adb:
adb uninstall com.reactnative02
expo start --android worked for me. This is assuming you're using expo of course.

Getting stuck on "Downloading Javascript bundle 100.00%" in expo app

Whenever I click 'run in iOS simulator' after running expo start in terminal, I'm getting stuck at a screen with "Downloading Javascript bundle 100.00%" in the app.
I'm creating a React native application and I tried all solutions including:
deleting Expo app
restarting simulator
erasing settings on simulator
rechecking code for bugs
Debug remote JS / stop remote debugging
See example of loading screen:
https://i.stack.imgur.com/RzEdZ.png
Delete your package-lock.json file, node_modules directory and then,
run npm cache clean -f.
Then run a new npm install as a regular user.
Finally, run an npm start again
try clearing the cache with expo start -c

Moved my React Native project folder to a new machine, how do i get it to run?

I recently cloned my React Native project folder from GitHub to my new/unused Mac. I am now in the root directory and when i run "react-native run-ios" to get the project going and load up the phone simulator, i get -bash: react-native: command not found
Do i need to re-install EVERY single dependency in package.json again (because it seems they're all there in my folders)?
Whats's the minimum in need to get my project up and running again and what commands do i use with my current project. I don't want to have to 'react-native init' an entirely new project!
Thanks
If you haven't done any react-native work on the Mac, then yes, you need to install all the dependencies including the react-native cli. You don't have the cli for react-native installed and you are trying to use it. You need to install react-native cli and NPM and make sure all dependencies are there.

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

react-native run-android command terminates by leaving a message in android simulator. The message 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.
What am I doing wrong?
You haven't started the bundler yet. Run npm start or react-native start in the root directory of your project before react-native run-android.
These steps really help me:
Step 1: Create a directory in android/app/src/main/assets
Linux command: mkdir android/app/src/main/assets
Step 2: Rename index.android.js (in root directory) to index.js (Maybe there is an index.js file in which case you do not need to rename it) then run the following 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 3:
Build your APK: react-native run-android
Please use index.js in latest version.
Enjoy :)
If you have everything correctly configured then try this:
adb reverse tcp:8081 tcp:8081
Why?
When the RN packager is running, there is an active web server accessible in your browser at 127.0.0.1:8081. It's from this server that the JS bundle for your application is served and refreshed as you make changes. Without the reverse proxy, your phone wouldn't be able to connect to that address.
All credits to Swingline0
.
A similar issue happened with me.
Apparently Mcafee blocks 8081 port. Took me hours to figure this out.
Try running:
react-native run-android --port=1234
When app shows up with an error on emulator, get into dev settings (Ctrl+M).
Change the "Debug server host and port for device" to "localhost:1234".
Close the app and start it from the app drawer.
For me this error was caused by an upgrade of react-native
Starting with Android 9.0 (API level 28), cleartext support is disabled by default.
If you check out the upgrade diff you need to create a debug manifest
android/app/src/debug/AndroidManifest.xml
<?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>
See for more info: https://stackoverflow.com/a/50834600/1713216
https://react-native-community.github.io/upgrade-helper/
You can try the following:
Add this line on your AndroidManifest.xml
<application
[...]
android:usesCleartextTraffic="true"
/>
[...]
</application>
EDIT:
Be careful, it must be false on production for the security of your app
just add three splash in :
node_modules\metro-config\src\defaults\blacklist.js
replace this part:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
First do steps 4 and 5 then you can run your project. If you do not get the result (with steps 4 and 5) do the following steps
1- Try to downgrade your Node version (current version is 12.13.1)
choco uninstall nodejs
choco install nodejs --version 12.8
2- Add the path of npm module (C:\Users\your user name\AppData\Roaming\npm) to system variables instead of user variables
3- Install react native globally by using command
npm install -g react-native-cli
4- Go to the root of your project directory and run the following command :
react-native start
5- Open another terminal in the root of your project and run the following command :
react-native run-android
EDIT :
You are using Genymotion ? If yes, do the following step :
After above step if you get the following error ?
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
Open your genymotion and go to :
genymotion menu -> Settings -> ADB -> Then select use custom android sdk tools (click on browse to find sdk location)
Finally , run you project again ..
In my case, the emulator's Wifi and Mobile Data was off.
[Quick Answer]
After try to solve this problem in my workspace I found a solution.
This error is because there are a problem with Metro using some combinations of NPM and Node version.
You have 2 alternatives:
Alternative 1: Try to update or downgrade npm and node version.
Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code:
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
and change to this:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
Please note that if you run an npm install or a yarn install you need to change the code again.
I've encountered the same issue while following the React Native tutorial (developing on Linux and targeting Android).
This issue helped me resolve the problem in following steps. Run following commands in the below sequence:
(in 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
You can automate the above steps by placing them in scripts part of package.json like this:
"android-linux": "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"
Then you can just execute npm run android-linux from your command line every time.
This worked for me after trying several ways.
In the file node_modules\metro-config\src\defaults\blacklist.js
Replace :
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
with :
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
hope this helps.
Starting with Android 9.0 (API level 28), cleartext support is disabled by default.
This is what you need to do to get rid of this problem if you do normal run commands properly
npm install
react-native start
react-native run-android
And modify your android manifest file like this.
<application
android:name=".MainApplication"
android:icon="#mipmap/ic_launcher"
android:usesCleartextTraffic="true" // add this line with TRUE Value.
android:theme="#style/AppTheme">
If you are on linux open the terminal from the App root directory and run
npm start
then open another terminal window and run:
react-native run-android
Like most of us I assume you are running on VSCODE. In my case, I ran
npx react-native start
from a seperate terminal
Now run npx react-native run-android from your terminal in VSCODE
My solution to this is as below:
Start Metro server
$ react-native start
Start Android
$ react-native run-android
If see errors saying "port 8081 already in use", then you can kill that process and rerun
$ react-native start
See React Native Troubleshooting Page .
After hours searching for a answer. The solution was to make a downgrade node to version 12.4.
In my case I realize that the error just occurs in version react native 0.60 with node version 12.6.
Hey guys a combination of 2 awnsers solved my problem. It was port related.
adb reverse tcp:8088 tcp:8088
react-native run-android --port=8088
By doing this, the app loaded fine of my phone connected by USB.
I think my AV or Vagrant or something elses in my PC was using that port.
You can change 8088 to something else if needed.
Enjoy!
I just want to add a non-obvious possibility not covered here. I am using #react-native-community/netinfo for detecting network changes, primarily network state. To test network-off state, the WIFI switch (on the emulator) needs to be switched off. This also effectively cuts off the bridge between the emulator and the debug environment. I had not re-enabled WIFI after my tests since i was away from the computer and promptly forgot about it when i got back.
There is a possibility that this could be the case for somebody else as well and worth checking before taking any other drastic steps.
I have also faced this issue. I resolved this following step.
Check android sdk path in Environment Veritable.
Add
ANDROID_HOME = C:\Users\user_name\AppData\Local\Android\Sdk in System Variable
and
C:\Users\user_name\AppData\Local\Android\Sdk\platform-tools path in System Variable
replace sharedBlacklist as below code segment,
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
in node_modules/metro-config/src/default/blacklist.js
Then run npx react-native run-android --port 9001
Happy Coding..!
I'm sure it some combination of the other things mentioned here like allowing clear text, which I enabled for localhost. But this was the final piece in the puzzle.
project.ext.react = [
entryFile: "index.js",
// ADD THESE THREE
bundleAssetName: "index.android.bundle",
bundleInDebug: true,
bundleInRelease: true
]
RN: 0.61.3
Apparently, none of the answers fixed the issue for me. I was able to run the react-native app on emulator but the same code (even when the Server was running), gave me this error when running the app on the device.
I was able to resolve it by executing the following command in the terminal:
adb reverse tcp:8081 tcp:8081
In my case I was trying to run the application on the emulator. But, I was getting this
This IP 10.0.2.2 was accessible from emulator chrome browser. The issue is that this IP is not whitelisted in Android Network Security Settings. So, whatever IP Address you are seeing here add that in below settings and you are good to go.
./android/app/src/main/AndroidManifest.xml
<application
android:name=".MainApplication"
+ android:usesCleartextTraffic="true" <- Add this line
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
./android/app/src/main/res/xml/network_security_config.xml
</network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.0.1.1</domain>
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">10.0.3.2</domain>
</domain-config>
</network-security-config>
Just replace <domain includeSubdomains="true">10.0.2.2</domain> with the IP you are shown in the error from react-native.
I was having the same trouble, the problem for me was that adb was not in the right environment path, the error is telling you metro port, while you're in the adb, ports are killed and restarted.
Add Enviroment Variable (ADB)
Open environment variables
Select from the second frame PATH variable and click edit option below
Click on add option
Submit the sdk platform tools path C:\Users\ My User \AppData\Local\Android\Sdk\platform-tools
Note: Or depending where is located adb.exe in your machine
Save changes
Run android build again
$ react-native run-android
Or
$ react-native start
$ react-native run-android
In my case, I've set a proxy in my emulator.
It works back to normal after I removing that proxy.
possibility of this error is also the wrong path,check once
export ANDROID_HOME=/Users/microrentindia/Library/Android/sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Here how I solved this issue without touching the build:
1- Closed the Virtual Device
2- Tested on Physical Device --(it works)
3- Created new Virtual Device with API 30 Android 10+
4- Try again on newly created Virtual Device, and all work like a charm.
I experienced this just because my Wifi was mistakenly turned off on my emulator.i turned it back on and it started working fine. Hope it's helpful to someone
For me this problem started with upgrading react-native. The upgrade was necessary to add 64-bit support.
Before:
--------
Environment:
Node: 10.15.0
npm: 6.9.0
Watchman: 4.9.0
Xcode: Not Found
Android Studio: 3.4 AI-183.6156.11.34.5692245
Packages: (wanted => installed)
react: 16.0.0-alpha.12 => 16.0.0-alpha.12
react-native: ~0.55.2 => 0.55.4
react-native-cli: 2.0.1
After:
------
info
React Native Environment Info:
Binaries:
Node: 10.15.0
npm: 6.9.0
Watchman: 4.9.0
SDKs:
Android SDK:
API Levels: 23, 26, 27, 28
Build Tools: 27.0.3, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: /undefined - /usr/bin/xcodebuild
npmPackages:
react: ^16.8.6 => 16.9.0
react-native: 0.59.9 => 0.59.9
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
Also, One important change that I made for the upgrade was in ../android/build/build.gradle
android {
...
defaultConfig {
...
targetSdkVersion 28
...
}
...
}
I had to change the targetSdkVersion from 27 to 28 following warning when I tried to upload the build(.apk) to goole play console.
Little did i realise that this was the root cause of the above error for me. Immediatly answers by #tom and #tinmarfrutos made absolute sense.
I solved the problem by adding android:usesCleartextTraffic="true" to my android/app/src/debug/AndroidManifest.xml
The solution that worked for me is the following:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];

React Native "The expo SDK requires Expo to run. .... this code is not running on Expo."

I am coding with React Native. I don't see that when I first create react-native app for check running. When I implements my code see that. My purpose is generate apk.
app.json
build.gradle
index.js (index.android.json)
App package.json
Solved
Result: I solved my problem with npm install. I would like say many month after.
If anyone's getting this error after upgrading Expo, try restarting your simulator - that fixed it for me.
Here is my experience if someone using expo sees those error message.
I accidentally installed expo manually in my project which was version 29.0.0.
I was using version 28.0.0 of expo sdk, so it may have crashed inside.
What I did:
manually upgrade sdkVersion of app.json to 29.0.0.
change sdk version to 29.0.0 for react-native.
Had exactly the same error - fresh machine, fresh npm, only one version of expo installed.
Turns out, expo requires you to build it as an app before it can send it to the expo app properly (at least on Android). This is easiest done by:
Adding an "android" section to app.json, with the contents "package": "uk.co.yourcompany.yourpackagename" (this is required by android packages. It can be complete garbage, but should follow that format - a backwards domain name)
running expo build:android and following the instructions to sign up to expo's servers and build the app
then restarting expo start
Not sure if this is documented anywhere though, so may be a new thing?
Another thing to try is to move your node_modules folder away (or maybe delete it, up to you) and re-run npm install
According to the official tutorial: https://facebook.github.io/react-native/blog/2017/03/13/introducing-create-react-native-app.html
If you want to use expo in your application, you must create it in the following way
npm i -g create-react-native-app
create-react-native-app my-project
cd my-project
npm start
This will start the React Native packager and print a QR code. Open it in the Expo app to load your JavaScript.
as I see your code has files that are not necessary, such as build.gradle and index.js, the structure that create-react-native-app creates is different and easier to use
I was getting the same error after updating the expo-cli to version 3.0.6.
By looking at my package.json I noticed the expo-cli version installed on my computer is not the same as package.json. so I changed it to "expo-cli": "^3.0.6" and ran npm install || yarn, then the error disappeared!

Resources