Closed luandro closed 6 years ago
You might need to recompile the android app
Gradle
Is there a react-native command for that? How does that work?
react-native run-android
I run it every time right after running react-native-node insert
, still Nodejs app doesn't get updated.
./gradlew clean
then run-android?
Took me a while to find out I had to brew install gradle
in order to use ./gradlew clean
in the android
directory.
Finally did, ran it successfully, but still get the first response written in the express server. Still seems the NodeJS apps aren't being rebuilt, despite running the whole thing every time:
"scripts": {
"dev": "npm run clean && npm run build && npm run android",
"build": "cd server && npm i && cd .. && react-native-node insert ./server",
"clean": "cd android && ./gradlew clean && cd ..",
"android": "react-native run-android"
},
Try one more thing: delete android/app/src/main/res/raw/rnnodebundle
before all that.
Added rm android/app/src/main/res/raw/rnnodebundle
to the clean script, but still nothing. No idea where the old code is coming from. It should only exist in rnnodebundle
, and if that's deleted and recreated with new code, how does it still persist?
Emulating on a MotoG3-TE - 6.0.
Oh emulators? I don't think this library works there, because node.js is compiled for ARM architectures, and emulators usually are not ARM.
Oh sorry, bad use of the word. I'm running the app on the actual phone (I was emulating using Geny Motion, but I read in #5 that emulators don't work).
Is there any thing else we can try?
Well, there is nothing else to try if you: (1) remove and rebuild rnnodebundle, (2) rebuild with gradle from scratch, (3) uninstall and reinstall the mobile app. Are you sure you have done those 3? There is no way the previous rnnodebundle can creep in after that
Got it fixed by using method (3), uninstalling the app on the device. Seems like the device caches the NodeJS application for some reason. Manually going to Settings > Applications > MyApp
on the phone and uninstalling it; when rebuilding with react-native the NodeJS application gets rebuilt.
Is there no programmatic way to to this?
Thanks for the help.
I added adb uninstall com.app_package
to my npm scripts, and that solved the problem. I guess this is usual for working with Node in react-native, to have to rebuild at every Node change, right?
I'll close this for now, thanks a lot for the help. Cheers!
Yeah, we have to rebuild after changes. Recompiling is a normal thing to do when developing mobile apps with Java and Gradle. React Native is what brings something completely new: runtime reloading. It would be a lot more work for me to build runtime reloading of the background process, so we do it the normal way: rebuilding
I think the uninstall was important because react-native-node unzips the rnnodebundle in an application directory, and only once (this is to avoid unzipping every time). So I think another way of solving the problem would be rebuild (after a gradle clean), clear the app's cache and data, then run
I'm running a simple express server like the example, and it works. But after changing the nodejs server and rebuilding with
cd server && npm i && cd .. && react-native-node insert ./server
the changes don't take effect any more.I've tried deleting
node_modules
on both the nodejs and the react-native apps, tried deleting thernbundle
that gets saved to theraw
folder. Nothing changes the express app once it's been built for the first time.