You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
We're cutting down on the number of outstanding issues, in order to allow us to focus. I'm closing this issue because it has been open for over 60 days with no activity. If you think it should still be opened let us know why. PRs are always welcome.
Description
When working on a Windows development environment with git's
autocrlf
configured astrue
, then repeatedly runningreact-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'sautocrlf
configured totrue
. 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
, thepatch
value is created with a trailing\n
. Later, inreact-native/local-cli/link/android/patches/isInstalled.js
, the code searches for this pattern in the project'sbuild.gradle
. On Windows, this will return -1 because the line ends with\r\n
rather than\n
. This causeslink
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
cantrim
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 tofalse
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
The text was updated successfully, but these errors were encountered: