|
| 1 | +--- |
| 2 | +id: libraries |
| 3 | +title: Linking Libraries |
| 4 | +layout: docs |
| 5 | +category: Guides |
| 6 | +permalink: docs/linking-libraries.html |
| 7 | +next: debugging |
| 8 | +--- |
| 9 | + |
| 10 | +Not every app uses all the native capabilities, and including the code to support |
| 11 | +all those features would impact in the binary size... But we still want to make |
| 12 | +easy to add these features whenever you need them. |
| 13 | + |
| 14 | +With that in mind we exposed many of these features as independent static libraries. |
| 15 | + |
| 16 | +For most of the libs it will be as simples as dragging two files, sometimes a third |
| 17 | +step will be necessary, but no more than that. |
| 18 | + |
| 19 | +_All the libraries we ship with React Native live on the `Libraries` folder in |
| 20 | +the root of the repository. Some of them are pure JavaScript, and you just need |
| 21 | +to `require` it. Other libraries also rely on some native code, in that case |
| 22 | +you'll have to add these files to your app, otherwise the app will throw an |
| 23 | +error as soon as you try to use the library._ |
| 24 | + |
| 25 | +## Here the few steps to link your libraries that contain native code |
| 26 | + |
| 27 | +### Step 1 |
| 28 | + |
| 29 | +If the library has native code, there must be a `.xcodeproj` file inside it's |
| 30 | +folder. |
| 31 | +Drag this file to your project on Xcode (usually under the `Libaries` group |
| 32 | +on Xcode); |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +### Step 2 |
| 37 | + |
| 38 | +Click on your main project file (the one that represents the `.xcodeproj`) |
| 39 | +select `Build Phases` and drag the static library from the `Products` folder |
| 40 | +insed the Library you are importing to `Link Binary With Libraries` |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +### Step 3 |
| 45 | + |
| 46 | +Not every library will need this step, what you need to consider is: |
| 47 | + |
| 48 | +_Do I need to know the contents of the library at compile time?_ |
| 49 | + |
| 50 | +What that means is, are you using this library on the native site or just in |
| 51 | +JavaScript? If you are just using it in JavaScript, you are good to go! |
| 52 | + |
| 53 | + |
| 54 | +This step is not necessary for all libraries that we ship we React Native but |
| 55 | +`PushNotificationIOS` and `LinkingIOS`. |
| 56 | + |
| 57 | +In the case of the `PushNotificationIOS` for example, you have to call a method |
| 58 | +on the library from your `AppDelegate` every time a new push notifiation is |
| 59 | +received. |
| 60 | + |
| 61 | +For that we need to know the library's headers. To achieve that you have to go |
| 62 | +to your project's file, select `Build Settings` and search for `Header Search |
| 63 | +Paths`. There you should include the path to you library (if it has relevant |
| 64 | +files on subdirectories remember to make it `recursive`, like `React` on the |
| 65 | +example). |
| 66 | + |
| 67 | + |
0 commit comments