I\'m trying to run my first React Native project for first time on my device (Android 4.2.2).
And I get:
unable to load script from assets in
If You are running your application on physical device and getting this error
unable to load script from assets index.android.bundle
try running the command:
adb reverse tcp:8081 tcp:8081
It workd for Me...
I've had this same issue for a number of months now. I initially used @Jerry's solution however, this was a false resolution as it didn't fully fix the problem. Instead, what it did was take every build as a production build meaning that any slight change you made in the app would mean that rebuilding the entire app is necessary.
While this is a temporal solution, it works horribly in the long term as you are no longer able to avail of React Native's amazing development tools such as hot reloading etc.
A proper solution is a shown:
In your MainApplication.java
file, replace the following:
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
with
@Override
public boolean getUseDeveloperSupport() {
return true;
}
as for some reason BuildConfig.DEBUG
always returned false and resulted in a bundle file in the assets directory.
By manually setting this to true, you're forcing the app to use the packager. This WON't work in production so be sure to change it to false or the default value.
Don't forget also to run
$ adb reverse tcp:8081 tcp:8081
OS: Windows
Another way to resolve this problem after trying two methods above
(because I installed SDK not in DEFAULT LOCATION like C:\users\"user_name"\appdata\local\sdk)
If you noticed that command line announced: "'adb' is not recognized as an internal or external command..."
So this is how I get over:
Examples: I installed SDK in D:\Android\sdk
So I will insert path in System Variables 2 more lines:
D:\Android\sdk\tools
D:\Android\sdk\platform-tools
(If you don't know how to edit path System Variables, here's the topic: https://android.stackexchange.com/questions/38321/what-do-i-type-in-path-variable-for-adb-server-to-start-from-cmd/38324)
Then I run cmd again: react-native run-android
It worked for me.
Using npm version 4.3.0 react-native-cli version 2.01 react-native 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
I spent hours trying to figure this issue out. My problem was not specific to Windows but is specific to Android.
Accessing the development server worked locally and in the emulator's browser. The only thing that did not work was accessing the development server in the app.
Starting with Android 9.0 (API level 28), cleartext support is disabled by default.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
See for more info: https://stackoverflow.com/a/50834600/1713216
Make sure metro builder is running to make your physical device and server sync
First, run this command to run metro builder
npm start
Then you can start the build in react native
react-native run-android
Their should be no error this time. If you want your code to be live reload on change. Shake your device and then tap Enable Live Reload