2015-03-27 03:12:55 +00:00
|
|
|
---
|
2015-03-30 19:18:33 +00:00
|
|
|
id: linking-libraries
|
2015-03-27 03:12:55 +00:00
|
|
|
title: Linking Libraries
|
|
|
|
layout: docs
|
|
|
|
category: Guides
|
|
|
|
permalink: docs/linking-libraries.html
|
|
|
|
next: debugging
|
|
|
|
---
|
|
|
|
|
|
|
|
Not every app uses all the native capabilities, and including the code to support
|
2015-03-31 04:22:39 +00:00
|
|
|
all those features would impact the binary size... But we still want to make it
|
2015-03-27 03:12:55 +00:00
|
|
|
easy to add these features whenever you need them.
|
|
|
|
|
|
|
|
With that in mind we exposed many of these features as independent static libraries.
|
|
|
|
|
2015-03-31 04:22:39 +00:00
|
|
|
For most of the libs it will be as simple as dragging two files, sometimes a third
|
2015-03-27 03:12:55 +00:00
|
|
|
step will be necessary, but no more than that.
|
|
|
|
|
|
|
|
_All the libraries we ship with React Native live on the `Libraries` folder in
|
2015-05-18 01:41:40 +00:00
|
|
|
the root of the repository. Some of them are pure JavaScript, and you only need
|
2015-03-27 03:12:55 +00:00
|
|
|
to `require` it. Other libraries also rely on some native code, in that case
|
|
|
|
you'll have to add these files to your app, otherwise the app will throw an
|
|
|
|
error as soon as you try to use the library._
|
|
|
|
|
|
|
|
## Here the few steps to link your libraries that contain native code
|
|
|
|
|
|
|
|
### Step 1
|
|
|
|
|
|
|
|
If the library has native code, there must be a `.xcodeproj` file inside it's
|
|
|
|
folder.
|
|
|
|
Drag this file to your project on Xcode (usually under the `Libaries` group
|
|
|
|
on Xcode);
|
|
|
|
|
2015-03-28 19:22:50 +00:00
|
|
|
![](/react-native/img/AddToLibraries.png)
|
|
|
|
|
2015-03-27 03:12:55 +00:00
|
|
|
### Step 2
|
|
|
|
|
|
|
|
Click on your main project file (the one that represents the `.xcodeproj`)
|
|
|
|
select `Build Phases` and drag the static library from the `Products` folder
|
2015-05-07 22:05:28 +00:00
|
|
|
inside the Library you are importing to `Link Binary With Libraries`
|
2015-03-27 03:12:55 +00:00
|
|
|
|
2015-04-01 19:47:20 +00:00
|
|
|
![](/react-native/img/AddToBuildPhases.png)
|
2015-03-28 19:22:50 +00:00
|
|
|
|
2015-03-27 03:12:55 +00:00
|
|
|
### Step 3
|
|
|
|
|
2015-03-28 19:22:50 +00:00
|
|
|
Not every library will need this step, what you need to consider is:
|
|
|
|
|
|
|
|
_Do I need to know the contents of the library at compile time?_
|
|
|
|
|
2015-05-18 01:41:40 +00:00
|
|
|
What that means is, are you using this library on the native side or only in
|
|
|
|
JavaScript? If you are only using it in JavaScript, you are good to go!
|
2015-03-28 19:22:50 +00:00
|
|
|
|
2015-03-31 04:22:39 +00:00
|
|
|
This step is not necessary for libraries that we ship with React Native with the
|
|
|
|
exception of `PushNotificationIOS` and `LinkingIOS`.
|
2015-03-28 19:22:50 +00:00
|
|
|
|
|
|
|
In the case of the `PushNotificationIOS` for example, you have to call a method
|
|
|
|
on the library from your `AppDelegate` every time a new push notifiation is
|
|
|
|
received.
|
2015-03-27 03:12:55 +00:00
|
|
|
|
2015-03-28 19:22:50 +00:00
|
|
|
For that we need to know the library's headers. To achieve that you have to go
|
|
|
|
to your project's file, select `Build Settings` and search for `Header Search
|
|
|
|
Paths`. There you should include the path to you library (if it has relevant
|
|
|
|
files on subdirectories remember to make it `recursive`, like `React` on the
|
|
|
|
example).
|
2015-03-27 03:12:55 +00:00
|
|
|
|
2015-04-01 19:50:13 +00:00
|
|
|
![](/react-native/img/AddToSearchPaths.png)
|