react-native-branch-deep-linking-attribution
react-native-branch-deep-linking-attribution copied to clipboard
`react-native link` doesn't always link libraries, frameworks, and update header search paths in `xcodeproj` file
In my existing project, the xcodeproj file was not updated with link libraries, frameworks, and update header search paths as expected. (See below, I created a clean react-native project and successfully installed react-native-branch and compared it to my own project to find the issue.)
The Fix v2
I was having the same issue using react-native link with another library… so I tried a couple things and found a better solution…
-
Remove all the Cocoapod files
Assuming you are using
gitsuch that you can revert this change…rm -rf ios/Pod* -
(Optional) Create
branch.jsonIf you want to use a
branch.jsonconfig file, it must be created before runningreact-native link react-native-branch. Read about installing with abranch.jsonfile. -
Install and link
react-native-branchIt's important that you use
react-native-branchwhen runningreact-native linkto limit linking to only thereact-native-branchlibrary.yarn add react-native-branch react-native link react-native-branch -
Revert (checkout) the deleted Cocoapod files
git co -- ios/Pod*At this point
git statusshould show the following modified files (with optionalbranch.jsonnew files):$ git status Changes to be committed: modified: android/app/build.gradle new file: android/app/src/main/assets/branch.json modified: android/app/src/main/java/com/hellokip/app/MainApplication.java modified: android/settings.gradle new file: branch.json modified: ios/kip.xcodeproj/project.pbxproj modified: package.json modified: yarn.lock -
Continue with Setup
Note: I typically do a git commit after running scripts to differentiate between changes made by scripts and those changed manually.
Continue with Setup
The Fix v1
-
Manually add
RNBranch.xcodeprojRight-click on PROJECT_NAME/Libraries and select 'Add files to "PROJECT_NAME"'.
Add "node_modules/react-native-branch/ios/RNBranch.xcodeproj"
-
Add
libreact-native-branch.ato Linked Frameworks and Libraries.Go to PROJECT_NAME > General > Linked Frameworks and Libraries.
Click +, and add
libreact-native-branch.a. -
Add Header Search Paths for react-native-branch
Go to PROJECT_NAME > Build Settings > Search Paths > Header Search Paths.
Add
$(SRCROOT)/../node_modules/react-native-branch/iosand select "recursive"
History
Originally I was getting the error:
/PATH/TO/PROJECT/AppDelegate.m:11:9: fatal error: 'react-native-branch/RNBranch.h' file not found
#import <react-native-branch/RNBranch.h>
I realized this after comparing a brand new react-native project and successfully installed react-native-branch using these steps:
react-native init foobar
cd foobar
yarn add react-native-branch
react-native link
I don't know why, but I suspect it may be because I'm using a .xcworkspace file because I am using Stripe or Intercom?
In case it's helpful, here's my Podfile:
platform :ios, '9.2'
target 'PROJECT_NAME' do
pod 'Stripe', '~> 11.2.0'
pod 'Intercom'
inherit! :search_paths
pod 'react-native-intercom', :path => '../node_modules/react-native-intercom'
pod 'react-native-branch', :path => '../node_modules/react-native-branch'
end
Thanks a bunch for taking the time to write this up Beau!
It seems to me this library was written before https://github.com/facebook/react-native/pull/15460 was merged / has not been updated to accommodate that change.
It seems that if you use Cocoapods at all in an existing project and try to install react-native-branch via link then it tries to use the .podspec files from this repo and it ends up not working at all.
I had to, as you suggest, first make it so react-native link would see my repo as not using
cocoapods:
pod deintegrate
rm Podfile
yarn add react-native-branch
react-native link react-native-branch
git checkout -- Podfile
pod install
and I was then finally able to get the library to build.
Yeah, ran into this problem as well. @beausmith's "The Fix v1" process finally ended up working for me after getting an Unknown symbol error from the Xcode linker while trying to compile.
Really wish the integration/installation process would work without having to dig in GitHub Issues
@beausmith Thanks for bringing up this issue! We will be taking a look to see if there is something we could do to improve this integration process.
@econner
I followed your way, but I am facing issues for running ios app.

This has been driving me crazy for some time, the 2x solutions at the top were not enough to resolve the file not found errors many continue to see as outlined in this thread... for the first time I am able to get my react-native: 0.49.9 app to build with these following steps:
// sourced from: https://github.com/react-native-community/react-native-camera/issues/1767
In ios/Podfile make sure you have the following set or else you may see when running
yarn start --reset-cache:
Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: /Users/{...}/node_modules/react-native/package.json collides with /Users/{...}/ios/Pods/React/package.json
rn_path = '../node_modules/react-native'
pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"
pod 'glog', :podspec => "#{rn_path}/third-party-podspecs/GLog.podspec"
pod 'React', path: rn_path, subspecs: [
'Core',
'CxxBridge',
'RCTAnimation',
'RCTActionSheet',
'RCTImage',
'RCTLinkingIOS',
'RCTNetwork',
'RCTSettings',
'RCTText',
'RCTVibration',
'RCTWebSocket',
'RCTPushNotification',
'RCTCameraRoll',
'RCTSettings',
'RCTBlob',
'RCTGeolocation',
'DevSupport'
]
do a full reset on your whole project:
git clean -fdx
yarn install
cd ios
pod install
cd ..
then start the installs:
yarn add react-native-branch
cp node_modules/react-native-branch/branch.example.json branch.json
react-native link react-native-branch
cd ios
pod install (may generate an error, recommending pod install --repo-update)
-> `pod install --repo-update` if receive the error
cd ..
Add #import <react-native-branch/RNBranch.h> near the top of the AppDelegate.m file.
Build app in Xcode
Currently, many of the documentations reference adding: #import <RNBranch/RNBranch.h> within AppDelegate.m - I don't know if this is correct or but seems to not work for me.
...
my ios app finally installs successfully after this
Thanks a bunch for taking the time to write this up Beau!
It seems to me this library was written before facebook/react-native#15460 was merged / has not been updated to accommodate that change.
It seems that if you use Cocoapods at all in an existing project and try to install react-native-branch via
linkthen it tries to use the .podspec files from this repo and it ends up not working at all.I had to, as you suggest, first make it so
react-native linkwould see my repo as not using cocoapods:pod deintegrate rm Podfile yarn add react-native-branch react-native link react-native-branch git checkout -- Podfile pod installand I was then finally able to get the library to build.
Hi @econner , I tried your solution that you mentioned. I got two errors:
- When I use
pod 'Branch-SDK', path: '../node_modules/react-native-branch/ios'in myPodfile, it still throws me the error[!] No podspec found for 'Branch-SDK' in '../node_modules/react-native-branch/ios'. - I fixed 1) by simply adding the
pod 'Branch'and it was able to install the dependency successfully. However, after that, I continued to follow the steps you had outlined in your post. I tried creating an archive for my app in Xcode11.4, which requires the app to build, and the build fails producing the error:'React/RCTLog.h' file not found. This keeps happening even if I manually add theRNBranch.xcodeprojto my Libraries list and add$(SRCROOT)/../node_modules/react-native-branch/iosrecursively, to theHeader Search Pathsas stated by @beausmith .
I wonder why this package cannot detect the file within the React dependency in Xcode, thus producing the two errors below:

Do you know how to resolve it @beausmith or @econner ? Your help will be greatly appreciated.
@celineotter , I also tried your method. When I was trying to run pod install after adding and linking react-native-branch, it seems as though the identified subspecs such as React/CxxBridge and DevSupport were not found. As an example, I got the following error:
[!] CocoaPods could not find compatible versions for pod "React/CxxBridge":
In Podfile:
React/CxxBridge (from '../node_modules/react-native')
None of your spec sources contain a spec satisfying the dependency: 'React/CxxBridge (from '../node_modules/react-native').
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
After getting the error, I tried running it with pod install --repo-update too but the error did not go away. It seems as though some of these subspecs no longer exist or are outdated within the React framework. I tried deleting the ones that were not found but there were many. So eventually, I had to remove all the subspecs and just leave pod 'React', path: '../node_modules/react-native' as is for the pods to be successfully installed.
I followed the steps that you highlighted very religiously, making sure I fully resetted the project and uninstalled and unlinked react-native-branch before linking it again but in the end, I could not successfully build my project as I kept receiving the error:
ld: library not found for -lBranch
clang: error: linker command failed with exit code 1 (use -v to see invocation).
It seems like the fix to this is to follow the steps from @econner above by ensuring the pods have disintegrated before adding this package dependency, which never gave me the above -lbranch error as it added the RNBranch.xcodeproj file successfully into the Xcode Libraries directory. However, even following @econner 's solution does not remove the 'React/RCTLog.h' file not found error I am still experiencing. Has anyone found a fix for this?
Really wish the integration/installation process would work without having to dig in GitHub Issues
Indeed, it would be nice if the package maintainers make integration of this package smooth: been stuck on this for more than a week now. For a full list of solutions that I have tried, please review my recently created issue: #609 .
Any help is greatly appreciated. Thanks :).
Sorry, I've been out of RN dev for a while. Gonna unsubscribe as I won't have anything useful to add going forward.