Patching React Native with patch-package not working - react-native

I'm trying to fix an issue in React Native, I forked the RN repo, added some code to some java files, and run the rn-tester App, my fix was working fine on the rn-tester App, but when adding this fix to a react-native package inside node_modules directory and patching it using patch-package, my fix not working even if I deleted the node_modules and installed them again, I see my code inside react-native java files but it have no effect on the App.
Also, any Log.d or System.out.println messages appear on the rn-tester App but don't appear on the other App.
added some code to /node_modules/react-native/ReactAndroid/.../somefiles.java that fixed an RN issue on the rn-tester App.
run npx patch-package react-native and inside package.json file under scripts added "postinstall": "npx patch-package" .
deleted node_modules and run npm i .
checked /node_modules/react-native/ReactAndroid/.../somefiles.java and my code existed.
run npm run android .
The RN issue still exists.
Expected
The code fixed the issue on the rn-tester App so it should fix it on the other App.

Because Rect Native takes its Java dependency as an AAR archive any changes to node modules will be skipped. You need to build react native from source as described here: https://reactnative.dev/contributing/how-to-build-from-source

Related

is it necessary to rebuild react-native project after linking

I would like to know if it's necessary to rebuild react native project after installing and linking libraries that includes native codes.
Yes, as react-native-link updates some native files that are under the ios/android folder, that won't be checked during a reload/hot-reload/live-reload. All those files aren't checked in your jsBundle and are compiled during a run-android or run-ios.
Of course, if you added a new dependecy to the project and linked it, and you haven't used it anywhere in your code yet, you don't need it. If you are using that dependecy, your project instance will, most likely, die.
if your react native version is below 0.60 then you have to run react-native-link after you install any react-native module. However after react-native version 0.60 and above, this is done automatically using the new "autolinking" feature added.
Read the changelog here:
https://facebook.github.io/react-native/blog/2019/07/03/version-60
However you still need to rebuild your project after you install a native module but you dont need to run the react-native-link command anymore after installing every library after react-native#0.60 and above. Just type react-native run-android

React Native missing script Android

I added a vector icon package in my React Native app. But After adding vector icon library I am trying to rebuild project using
**npm run android
react-native link**
But it's giving me an error
npm err missing script android react native
I have tried many solutions of updating package.json file from Github and I have tried to change the path of the environment but still same
I think you are using the wrong command to make debug build.
Following these steps:
install vector icon
link it from your project root directory using the command react-native link your_package_name
Use this command from your project root directory to make build react-native run-android

How to reload node_modules' jar and js?

I have some react-native questions:
1) I have added some console.log() in
node_modules\react-native\ReactAndroid\src\androidTest\assets\AndroidTestBundle.js
However, when I try "react-native run-android" in Windows command, the debug panel does not show it. Should I run another command before run-android?
2) In addition, I have changed the java files in
node_modules\react-native\android\com\facebook\react\react-native\0.42.3\react-native-0.42.3-sources.jar
but it seems that it does not auto compile the jar again. Should I run any command first?
Thanks.
For your first question:
The React Packager usually doesn't listen to any changes to files inside the node_modules folder. If you make any changes to JS files inside the node_modules folder, then you will have to kill the packager (ctrl+c) and start it again using react-native start command. Then you can see the result of modifications to JS files inside the node_modules folder
And for your second question:
React Packager cannot compile native code in real-time it only compiles the JS files and delivers them to the device. So, if you make any changes to native code JAVA/Swift or Obj-C(for iOS) you need to build the app again using react-native run-android command for Android, react-native run-ios for iOS simulator. (manually re-run the build through XCode if you are testing on real iPhone)

React native RTCRootView.h not found

I'm trying to use React native and I am getting an error in xcode that says "Lexical or preprocessor error 'RTCRootView.h' not found." I have checked and this file is in the framework folder and I have tried moving it into the project as well and still have not been able to eliminate the error and successfully build.
In the example directory, run npm install to install the dependencies.
Then, open swipeoutExample.xcodeproj and run.
react-native-swipeout#15.
edit (2015-10-12):
react-native-swipeout has been updated to use the latest react-native including ./ios and ./android directories.
iOS: Open the xcode project in the ./ios directory and run it.
Android: Start a simulator, then run react-native run-android in project root directory. (note: swipeout is currently incompatible with Android, but will be soon.)
Running npm install might work for some people, but it didn't work for me.
What worked for me was in XCode > Product > Clean
Sometimes it might be because the node_modules folder is missing in your project directory.
Move the node_modules folder to your project
run npm install in your project directory
Just faced with the same error. In my case it was because of typing error. I replaced RTCRootView.h with RCTRootView.h (RCT is an abbreviation of ReaCT).

Installing npm modules makes flex crash with type errors

I'm attempting to use a component in my React Native project, specifically this one:
https://github.com/lucholaf/react-native-grid-view
I run npm install react-native-grid-view in the project's directory, but as soon as I do that, after building I get:
Is the problem that I'm running npm install in the wrong location? I've tried other directories, but then React doesn't see the modules and says "unknown module".
Thanks!
The problem was that the component was pointing to an older version of React Native, 0.3.4. Manually updated to 0.4 and it worked.