Description
Description
When working on a Windows development environment with git's autocrlf
configured as true
, then repeatedly running react-native link
will repeatedly add the same dependencies to the Android app's MainApplication.java, instead of recognizing that the library has already been linked after the first invocation.
Reproduction
Run react-native link
repeatedly on a Windows environment with git's autocrlf
configured to true
. This will add the dependencies multiple times to the MainApplication.java file. I can provide a sample project if required.
Solution
I suspect the reason is that in react-native/local-cli/link/android/patches/makeBuildPatch.js
, the patch
value is created with a trailing \n
. Later, in react-native/local-cli/link/android/patches/isInstalled.js
, the code searches for this pattern in the project's build.gradle
. On Windows, this will return -1 because the line ends with \r\n
rather than \n
. This causes link
to apply the patch again.
One way of fixing this is to use Node.JS's os.EOL
rather than \n
, but I'm too new to react-native to know if it's fine for react-native's build process to depend on NodeJS-specific libraries (rather than pure JavaScript).
Alternatively, isInstalled
can trim
the line before searching for it. However, the code will still insert the patch with a \n
into the patched files (though git will then correct the newlines).
Of course, if I worked with autocrlf
set to false
on my machine then I wouldn't be having this problem, but this isn't the recommended way to work on Windows - see e.g. the Github documentation.
Additional Information
- React Native version: 0.42.3.
- Platform: Android.
- Development Operating System: Windows.