Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop react-native link from linking a library with CocoaPods with it has a podspec?

I need to use CocoaPods for a specific library. However I don't want to use it for any other because it usually forces me to add React and its dependencies to the Podfile as well, which is a nuisance and can lead to several issues as in previous experiences.

In React Native documentation (https://facebook.github.io/react-native/docs/linking-libraries-ios) it is specifically said:

If your iOS project is using CocoaPods (contains Podfile) and linked library has podspec file, then react-native link will link library using Podfile. To support non-trivial Podfiles add # Add new pods below this line comment to places where you expect pods to be added.

Is there any way to prevent this? If not, what is the best Podfile configuration that doesn't break (when RN is updated for example)?

like image 977
jphorta Avatar asked Aug 30 '18 14:08

jphorta


1 Answers

The solution that I use is really a workaround. It is not great but it works for me. Ideally it would be nice if react-native link offered a -noPods flag but it doesn't.

react-native link checks to see if there is a Podfile, if there is no Podfile it links the dependency as normal.

So what I do is the following:

  1. Make sure I have committed all the changes to git.
  2. I then install the dependency using yarn or npm.
  3. I delete the Podfile.
  4. I run react-native link dependency_name
  5. I then discard the changes to the Podfile (effectively undeleting it)

Alternatively you rename the Podfile to something else, and then rename it back after you have linked.

like image 167
Andrew Avatar answered Oct 17 '22 16:10

Andrew