12

I'm using React Native 0.60.5 and am linking this module. It says that for React Native 0.60+, "CLI autolink feature links the module while building the app", so all we need to run is yarn add @react-native-community/async-storage.

However, on the main page describing autolinking it says that we need to run:

yarn add @react-native-community/async-storage cd ios && pod install && cd ..

What I Want To Know:

Do we have to run pod install for all native modules with React Native 0.60+?

gkeenley
  • 6,088
  • 8
  • 54
  • 129
  • After installing each native library that needs to link, you have to run `pod install` command. – Hamed Navabian Sep 13 '19 at 21:12
  • I thought that `pod install` just linked the native module, and that that's what auto-linking was accomplishing automatically. What am I missing here? – gkeenley Sep 13 '19 at 21:25
  • Some will get auto-linked, others will add the dependency inside pod and you'll have to install em – Auticcat Sep 13 '19 at 21:37
  • @Auticcat So some native modules will get auto-linked, whereas others won't get auto-linked but will add a dependency in my Podfile, and I should do `pod install` to link them? If one of them gets auto-linked and then I try to manually link it with `pod install` as well, would that do nothing since it was already auto-linked? – gkeenley Sep 13 '19 at 21:53
  • Any react native library that uses a native iOS library will need `pod install` – Saadi Sep 14 '19 at 06:01

1 Answers1

7

There are 2 types of linking in react-native

1 ) Manual linking

2 ) Pod linking

As described in official site

"If your iOS project is using CocoaPods (contains Podfile) and linked library has "podspec file", then react-native link will link library using Podfile."

Now when you

 react-native link

If you project has CocoaPods (contains Podfile) and linked library has podspec file then it will add pod path of linked library in podfile like this

pod 'RNImageCropPicker', :path =>  '../node_modules/@react-native-community/async-storage'

But you still have to run pod install command

If project does not have pod file or linked library does not have podspec file then you have to do manual linking as described in site

Now coming to question from react-native 0.60 this process is now automatic. You do not have to run "react-native link " . It will automatically do pod work for you when you install library using npm/yarn but still you have to run "pod install" command

Mehran Khan
  • 3,616
  • 1
  • 13
  • 10
  • When I do manual linking, I drag the `.xcodeproj` file to the Libraries folder, then drag the `.a` file from the `.xcodeproj` file to the "Link binary with libraries" section. Is this the 'linking' process that `pod install` does? In other words, if I manually link like this, is there any benefit to doing `pod install`? – gkeenley Sep 17 '19 at 16:12
  • 1
    I think the benefit of pod install is that you do not have to do any thing thing manually, Just run command and all done , on other hand you have to do all manual steps – Mehran Khan Sep 18 '19 at 03:30
  • So am I correct that all that `react-native link` does (pre-React Native 0.60) is add a line for the module to your Podfile, and then you have to do `pod install` yourself? In other words, with auto-linking, all it does is automatically add the line to your Podfile so you don't have to, but you still have to run `pod install`? Second question, when I manually linked before, I dragged the `.xcodeproj` and `.a` files into their corresponding spots in XCode. Is that all that `pod install` does? – gkeenley Sep 18 '19 at 16:44
  • And last question (thanks for your patience), in the last year, I've never used `pod install`. I just ran `react-native link` and this successfully linked some modules, but not all. The ones that it didn't link, I linked manually. So it seems as though `react-native link` was doing more than just adding a line to my Podfile (which I never used); it was actually linking modules. Any idea what was happening there? Thanks again! – gkeenley Sep 18 '19 at 16:46
  • Just to be sure: if I'm opting to use `pod install`, the pod linking will also take care of dependencies and linking on the Android side of things, is that correct? – Atticus Oct 20 '22 at 18:19