I created a library that uses the native navigation controller to navigate through react and native screens. The library is written in Swift and contains some objective-c code to setup the React bridge etc. Currently I can distribute this library through CocoaPods by creating a podspec and defining the React dependency there. However, this forces the user to setup React in their project through CocoaPods as well (like so: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html). I'd like them to use the react-native link or manually linking option as well (like so: https://medium.com/@joshyhargreaves/adding-react-native-to-existing-ios-project-without-cocoapods-6f1ee9106009). If I understand correctly I can create a static library and distribute that. So far I created this static library, added my mixed swift and objective-c code and tried to manually link it into my main project. This however produces an error in one of my classes inside my static library where I import React like so import React. Error is "No such module 'React'. I updated the Header Search Paths of my static library to contain: $(SRCROOT)/../react-native/React and $(SRCROOT)/../React (react-native, React and my own lib are all inside the node_modules folder) both set to recursive. Unfortunately it still doesn't find the module React. Does anyone know how to create a static library that contains a dependency with React? The end goal would be to import this static library in my main project like import MyStaticNaivationLib in one of my viewcontrollers and subclass from a class that's defined in my static library. My main project also uses https://github.com/rebeccahughes/react-native-device-info. This looks exactly what I want to achieve. It's a static library that has a dependency with React ("import RCTBridgeModule.h") which I can manually link in my main project. Only difference is that this project doesn't contain Swift code.
top of page
bottom of page
To create a static library that includes a dependency on React in your project, you'll need to follow these steps:
In your static library project, make sure you have the React dependency installed. You can install it by running npm install react in your static library project's root directory.
In your static library project's build settings, add the path to the React headers to the "Header Search Paths" setting. This should be the path to the React directory inside the node_modules directory in your static library project.
In your static library project's build settings, add the path to the React library file to the "Library Search Paths" setting. This should be the path to the libReact.a file inside the node_modules/react/ios directory in your static library project.
In your static library project's build settings, add the -lReact flag to the "Other Linker Flags" setting. This will link the React library to your static library.
In your main project, add the path to your static library to the "Library Search Paths" setting in the main project's build settings.
In your main project, add the -lMyStaticNaivationLib flag to the "Other Linker Flags" setting in the main project's build settings. This will link your static library to the main project.
In your main project, add `#import <MyStatic