iosreact-nativereact-native-iossegment-io

Why does not react-native-link work for `@segment/analytics-react-native` library?


I am trying to link the @segment/analytics-react-native library in my iOs react-native project.

I followed these two steps given in their docs.

  1. yarn add @segment/analytics-react-native
  2. yarn react-native link

However the yarn react-native link step doesn't seem to work, as all it does is add a pod in the podfile, and modify some android project files that I don't need.

The project.pbxproj file is showed as modified but when I inspect it inside vs code, the only thing it does in that file is removing a line.

Please explain why is this happening


Solution

  • From the docs about linking

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

    This means that it will not add the dependencies inside your Xcode project.

    If you are happy with this then make sure you cd into you iOS folder and run pod install

    If you don’t want it installed via CocoaPods then you can either install it manually using the instructions on the dependencies repo (remembering to delete the line added to your pod file); or you can rename your podfile, run react-native link so it adds the files without the updating the podfile, then rename the podfile back to what it should be.

    One further point to note you shouldn’t run react-native link without the dependency name. You should run react-native link <dependency name>. You can end up with duplicate entries and unforeseen issue if you don’t.