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
I had issue with McAfee on my mac blocking port 8081, had to change it to 8082.
First run your package server:
react-native start --port 8082
Open another terminal, start the android app as usual:
react-native run-android
Once it finishes, now rewrite the tcp port that adb tunnels:
adb reverse tcp:8081 tcp:8082
See the list of adb tcp tunnels:
adb reverse --list
You should now see a heartwarming message:
(reverse) tcp:8081 tcp:8082
Go to your app and reload, done!
PS: Don't change anything in the app Dev settings, if you added "localhost:8082", just remove it, leave it blank.
EDIT: To all the McAfee victims out there, there's easier solution if you have root access, just temporarily kill the McAfee process sitting on port 8081 and no need for port change at all:
sudo launchctl remove com.mcafee.agent.macmn
It may be caused by unlinked assets in your React Native project code base, like when you renames your project application/bundle id or adds an external package without link it properly, for example.
Simply try it in your project root directory:
react-native link
react-native run-android
For all of you guys who are developing from a create-react-native-app and ejected, and have this issue in development
,
this is what worked for me
just a little detail from the accepted answer
(in project directory) mkdir android/app/src/main/assets
here comes the part that changes cos you are in development get rid of the --dev: false
part:
react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
after that close all terminals, erase the build folder from android/app/ to make sure you start clean to build your app, open a new terminal, and
(in project directory) npm run android
will prompt the packager console (in another terminal) and build successfully
For this problem I just solve it by running:
react-native start
then
adb reverse tcp:8081 tcp:8081
on command line. And then i can run:
react-native run-android
So i will not waste my time to run:
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
every time.
Ubuntu
first time, I created new app with react-native init project-name
.
I got the same error.
so i do the following steps to resolve this in my case.
sudo chown user-name-of-pc /dev/kvm
in my case.While debugging from your Android phone, select Use USB to Transfer photos (PTP)
.
Create Folder assets
in project-name/android/app/src/main
index.js
be avaiable into your project root
directory and then run below command from console after cd project-name
directory.
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
or for index.android.js then
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
run command ./studio.sh
in android-studio/bin
directory. It will opens up Android Studio.
run command react-native run-android
.
In my case, I have removed below line from MainApplication.java. (Which is previously mistakenly added by me.):-
import com.facebook.react.BuildConfig;
After that Clean Project and hit command
react-native run-android