DRDD2016 / sparkn2

0 stars 1 forks source link

Linking libraries with native code #57

Closed minaorangina closed 7 years ago

minaorangina commented 7 years ago

Note

22-12-2016 This is necessary for 3rd-party modules that use native code, not for modules that ship with React Native

In particular, this is not necessary for the React Native Linking library, contrary to what the docs currently say.

minaorangina commented 7 years ago
  1. Open project's directory in your computer. Go to: node_modules/react-native/Libraries/[library name].
    You'll find a file called: RCT[library-name].xcodeproj.
  2. Open your project in xcode by running:
    $ open ios/[your-project-name].xcodeproj
  3. In the navigation bar on the left, open [your-project-name]/Libraries

Note: We found that the react-native library we were interested in (Linking) was already in the xcode project tree under the Libraries directory - it was called RCTLinking.xcodeproj. If this is the case for you, you can skip steps 1-3.

  1. Now open [your-project-name]/Libraries/RCT[library-name].xcodeproj/Products. You'll find a file called libRCT[library-name].a
  2. Now click on the root of your project at the top of the left-hand navigation bar, with the blue icon.
  3. In the main screen to the right, you'll see a navbar. Look for Build Phases and open it up.
  4. Inside Build Phases, open up Link Binary With Libraries
  5. Drag your libRCT[library-name].a file from the navigation bar to the Link Binary With Libraries section.

There's an extra step for certain libraries, see here to decide if this is necessary for you.

If so:

  1. Click on the root of your project at the top of the left-hand navigation bar, with the blue icon.
  2. In the main screen to the right, you'll see a navbar. Look for Build Settings and open it up.
  3. Under Build Settings, find the Search Paths subcategory. Open up Header Search Paths
  4. You'll see a directory path to the right of Header Search Paths. Double-click the directory path to open up a small modal window.
  5. In the modal window, click the + on the bottom-left to add a new path. You will need to add the path to the library you want to link (it will be under your node_modules directory somewhere). For the libraries that ship with React Native (e.g. LinkingIOS or PushNotificationsIOS), enter your path as:
    $(SRCROOT)/../node_modules/react-native/Libraries/[library-name]`

    If the library folder has 'relevant' files in nested subdirectories, you will need to register the header as recursive. Otherwise, non-recursive is fine.

After this, click the Run button (looks like a 'play' button) at the top-left of the xcode window to build your project. If all goes well, should receive a Build Succeeded message.

minaorangina commented 7 years ago

This issue was moved to DRDD2016/native#43