unable to load script from assets 'index.android.bundle'.- React Native - android

I have run a React Native project on Windows by using react-native run-android command. I got the following error in the emulator:
Unable to load script from assets 'index.android.bundle' .Make sure your bundle is packaged correctly or you are running a package server.
I tried these links but not work with me.
Unable to load script from assets index.android.bundle on windows.

I had the same error in the same context, and it was simply because the app launched before the development server finished to bundle up the files. Make sure you wait untill the node development server displays:
Loading dependency graph, done
and hit reload on the app.

Go to your project folder android/app/src/main/assets
Delete index.android.bundle and index.android.bundle.meta
If assets directory not there create new one.
Go to root project > cd android
./gradlew/clean
In root folder run following command if there was index.js file
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
If there are two files index.android.js and index.ios.js then 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
Above two are single line commands.

Related

metro error when running react native app from apk file

i have a react native app and im able to run it when i connect my phone and run the command react-native run-android but when i go to github and download the apk file from android/app/build/outputs/apk/debug/app-debug.apk and install the app i get this
i have android:usesCleartextTraffic="true" but i dont know what else to do
use below commands to create debug apk
1.
npx 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 assembleDebug

React Native Android runs in dev but not with release [duplicate]

Android Studio is generating very old apk for react-native project like 3 months old. But running perfectly in emulator while running this command "react-native run-android"
Process -
* Open file location
* Build => Build Bundles => Build APK
Tried re-installing android studio but still getting old APK
In the old react-native version, when we generate the android APK, sometimes the bundle is old, we have to generate it by ourself.
In the react-native 0.61, I find the problem is dismissed.
In the old version, firstly you should add the following script to the package.json
"scripts":{
...
"bundle-android": "react-native bundle --entry-file index.js --platform android --dev false --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res",
...
}
the when you generate the apk , you firstly run the follwing script in the termail to generate the new bundle
npm run bundle-android
when the bundle outputs successfully, then go into the android directory and assemble the APK
cd android
./gradlew assembleRelease
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/
If you get an error of duplicate resources than go to res folder and delete the drawable-hdpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi,drawable-xxxhdpi folder only and try to rebuild the project. It will work.
It is because, you have old index.android.bundle file. Follow these steps to update this file and create a new apk:
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
curl "http://localhost:8081/index.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
cd android && ./gradlew clean assembleDebug

Android app with react-native works on emulator but doesn't on physical device

I think title explains itself my problem, on emulator everything works as it should be, when apk builded I have transfered it on my smartphone and there's errors:
https://imgur.com/a/pSEKXHx
I was have the same issue when i assemble Release/Debug apk and install it on my physical smartPhone
Do this commands in your Project Directory :
mkdir android/app/src/main/assets
(if you have the assets folder you will see error like directory is already exist ... no problem! go to next 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
react-native run-android or assemble the apk
it should work GOOD LUCK

React-native run-android builds the correct version of my app, but assembleRelease/ react-native run-android --variant=release do not

When I run react-native run-android the correct version of my app runs on both the emulator and a physical device. However, the moment I try to run ./gradlew assembleRelease or react-native run-android --variant=release I get an older version of the app. I've tried running ./gradlew clean before running assembleRelease. I've also tried manually deleting the apk and json files. But I keep getting an old version of the app which doesn't have all the new features.
EDIT: Using the directions from this post. I was able to get the new version to load, however, I lost all of the new images that came with the newer version. Any ideas how to make sure the images are loaded
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest andro id/app/src/main/res
Originally from this SO post
https://github.com/react-community/lottie-react-native/issues/269
Go to your project directory and check if this folder exists android/app/src/main/assets i) If it exists then delete two files viz index.android.bundle and index.android.bundle.meta ii) If the folder assets doesn't exist then create the assets directory there.
From your root project directory do cd android && ./gradlew clean
Finally, navigate back to the root directory and check if there is one single entry file called index.js i) If there is only one file i.e. index.js then run 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
ii) If there are two files i.e index.android.js and index.ios.js then run this 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

Unable to load script from assets 'index.android.bundle',Make sure your bundle is packaged

I have made sure that bundler and emulator are running.
If I use this commend
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
It might work but refresh won't happen when I press rr in emulator.
I have also tried reversal of abd adb reverse tcp:8081 tcp:8081.
Nothing works for me.
click here to see the error screen.
To resolve Unable to load script from assets index.android.bundle - React Native follow below process :
You have to create dir assets manually in your android project or make Directory by Terminal/CMD enter mkdir android/app/src/main/assets
Go at the created Directory if that is successfully created then
run step 3 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
you have your missed files in the folder now you can Run your React Native project npm run android.
Sometimes you have to clear the cache to load your assets properly.
Use the command react-native start --reset-cache
and re-run react-native run-android
I had this issue after having had it work for the past couple days. I realized that I had manually configured a proxy. As soon as I turned that off, it worked.
For me, Gradle clean fixed it when I was having an issue on Android
cd android
./gradlew clean

Categories

Resources