When I run react-native run-android it only installs the old version of the app in simulator and changes are not shown.
Any suggestion is appreciated.
When I run react-native run-android it only installs the old version of the app in simulator and changes are not shown.
Any suggestion is appreciated.
Seems like we have to re-bundle assets every time we compile it to android app. This worked for me:
First run this:
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
Then this:
react-native run-android
Have you tried react-native start --reset-cache
?
Or maybe you can try to reset the MAX_WAIT_TIME
(I found it here).
in file \node_modules\node-haste\lib\FileWatcher\index.js
you should increase MAX_WAIT_TIME
variable (example : 360000) and change function _createWatcher.
From:
key: '_createWatcher',
value: function _createWatcher(rootConfig) {
var watcher = new WatcherClass(rootConfig.dir, {
glob: rootConfig.globs,
dot: false
});
return new Promise(function (resolve, reject) {
var rejectTimeout = setTimeout(function () {
return reject(new Error(timeoutMessage(WatcherClass)));
}, MAX_WAIT_TIME);
watcher.once('ready', function () {
clearTimeout(rejectTimeout);
resolve(watcher);
});
});
}
To:
key: '_createWatcher',
value: function _createWatcher(rootConfig) {
var watcher = new WatcherClass(rootConfig.dir, {
glob: rootConfig.globs,
dot: false
});
return new Promise(function (resolve, reject) {
const rejectTimeout = setTimeout(function() {
reject(new Error([
'Watcher took too long to load',
'Try running `watchman version` from your terminal',
'https://facebook.github.io/watchman/docs/troubleshooting.html',
].join('\n')));
}, MAX_WAIT_TIME);
watcher.once('ready', function () {
clearTimeout(rejectTimeout);
resolve(watcher);
});
});
}
May it help you! :D
Tried with the solutions above, not sure if they helped for the final version, but what worked at the end was running ./gradlew clean assembleRelease
in the /android
folder.
Check for any syntax errors that might not be highlighted by VS code.
After three hours of pulling my hairout turns out it hadnt alerted my to an =
instead of a :
in an object.
I had this happen while working with iOS, and here are the steps I took to get back to working order:
$ react-native start --reset-cache
$ rm -rf ios/build
Doing this much on its own will force RN to rebuild the iOS version from scratch when you run yarn ios, so this could be answer for most anyone else running with iOS.
In my latest encounter of this issue, I found that after forcing a new build, metro-bundler would throw the following error: Metro Bundler has encountered an error: SHA-1 for file < some file in node_modules >
With this, I had to refresh my node_modules in order to resolve the issue completely.
$ rm -r node_modules
$ yarn
For me I simply restarted my system. Or simply stop the react-native server, then re-run your app.
Another way to fix this problem is to run this command in your web browser console. I had this problem with React Native for Windows and none of the above solutions worked for me.
localStorage.clear()
The problem is that projectroot > ios > main.jsbundle is not updating as it is supposed to with code changes/builds. To get current, delete that file. Then in Terminal ( only here, do not rely on automatic creation ), put: react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios/assets
This will create a current main.jsbundle which is used to create the app and also what is used for creating an archive. Problem is, if you update your code, you have to do it again.
You can edit main.jsbundle by hand if you need to. I had to tweak it so some of my images showed up when I had multi-layer folders/pages. Not hard, just search for your image name and look at/edit the link.
This is my solution for debug / release N.B. - if you're using expo - this is probably not applicable.
yarn android:bundle:debug should get latest debug version... assumes you're using index.js as main entry point.
Add these to your package.json
"scripts": {
"android": "npx react-native run-android",
"android:bundle:debug": "react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/",
"android:bundle:release": "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/build/intermediates/res/merged/release/",
}
release.sh
yarn android:bundle:release
cd android
./gradlew bundleRelease
cd app/build/outputs/bundle/release
open .
I was creating a staging
buildType in my react native project too, the build was fine (after dealing with some problems), but for some reason it was loading an old version of the app too.
After changing the buildType from staging
to releaseStaging
, it started to build as expected and to load the correct version.
I've answered in another topic too with more specific instructions.