2

I'm using React Native 0.61, and have been reading about the new auto-linking feature. If you have any insight on ANY of the following questions, I'd appreciate it.

My Questions Are:

1) My understanding of react-native link <module> is that it adds a line for <module> to your Podfile, and then you run pod install. However, for the last year I've been using react-native link and linking manually, and have never run pod install. So am I right that react-native link does more than just add lines to your Podfile?

2) In the past, when react-native link failed to link the module, I manually linked it by dragging the .xcodeproj and .a files into Xcode as described here. Does react-native link (when it works) add the line to your Podfile AND add .xcodeproj and .a files into Xcode for you?

3) Is there anything involved in native modules being linked other than the .xcodeproj and .a files being added to Xcode?

4) What exactly does pod install do? Does it take all the native modules referenced in your Podfile and add .xcodeproj and .a files into Xcode? If so, that would involve two steps: adding the line to your Podfile and then running pod install. Why not just react-native link?

5) My understanding of auto-linking is that it adds lines for all native modules to your Podfile, and then you still have to run pod install. Isn't this just accomplishing the same thing as react-native link?

6) In this guide to auto-linking, it says "Autolinking is a replacement for react-native link. If you have been using React Native before version 0.60, please unlink native dependencies if you have any from a previous install.". Why does it tell you to unlink? If the module is already linked, what will unlinking it and re-linking it do? This implies there's a difference between the way modules are linked with react-native link and via auto-linking. What happens if you auto-link and then pod install, and then try using react-native link, or vice versa?

7) I outlined this in the previous questions, but just to make it concise, what is the difference between auto-linking + pod install and react-native link?

Nald Dev
  • 557
  • 5
  • 15
gkeenley
  • 6,088
  • 8
  • 54
  • 129
  • If you come from a javascript background, think of "pod install" as "npm install" for a cocoapods project, ie. your iOS app. This just installs all of the dependencies that are specified in your xcode project by react-native. – Hannes Hertach Oct 20 '19 at 17:10
  • @HannesHertach Thank you. I do understand conceptually the role of `pod install`. If you have any insight into my specific questions here I'd really appreciate it. – gkeenley Oct 20 '19 at 17:12

1 Answers1

5

All of your questions are closely intertwined so I'm going to just give you the details that will hopefully clear up things for you.

If React Native version <= 0.59 AND Cocoapods is NOT used in the project :

react-native link will just add the .xcodeproj file and the .a file to the XCode Project. It will NOT add any lines to the Podfile because in this case, the Podfile doesn't exist.

If React Native version <= 0.59 AND Cocoapods is used in the project :

react-native link will add the lines to the Podfile and install pods. It will NOT add .xcodeproj or .a file to the XCode Project. This is assuming that the library supports Cocoapods installation. How do you know if the library supports Podfile installation ? They mention it on their Github page/NPM page. Also, such libraries will have a .podspec file as well. Example : https://github.com/react-native-community/react-native-device-info See that this library has a .podspec file -> RNDeviceInfo.podspec. So this supports Cocoapods installation. If the library doesn't support Cocoapods installation, react-native link will just add xcode.proj and .a file to the XCode Project like the above case.

If React Native version >= 0.61 (Cocoapods is default in this case)

react-native link is NOT required anymore. You just install the library (yarn add or npm install) And then do pod install. What happens here is, Cocoapods grabs the library from the node_modules folder, checks if there is a .podspec file and then installs the pods. But it DOESN'T add any lines to the podfile. This is auto-linking that's been introduced in React Native version 0.60. In case of older libraries that DO NOT have a .podspec file, you need to manually link the library by react-native link.

user3055126
  • 249
  • 3
  • 12
  • Ty for this explanation. I trust that what you are saying is correct but is there some documentation you can provide that supports what you are saying? Would like to read more about this. – Sean Dunford Oct 13 '20 at 03:48