Patching React Native with patch-package not working

2.9k views Asked by At

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.

1

There are 1 answers

0
Kirill Novikov On BEST ANSWER

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