react-native-branch-deep-linking-attribution icon indicating copy to clipboard operation
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

Open beausmith opened this issue 6 years ago • 8 comments

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…

  1. Remove all the Cocoapod files

    Assuming you are using git such that you can revert this change…

    rm -rf ios/Pod*
    
  2. (Optional) Create branch.json

    If you want to use a branch.json config file, it must be created before running react-native link react-native-branch. Read about installing with a branch.json file.

  3. Install and link react-native-branch

    It's important that you use react-native-branch when running react-native link to limit linking to only the react-native-branch library.

    yarn add react-native-branch
    react-native link react-native-branch
    
  4. Revert (checkout) the deleted Cocoapod files

    git co -- ios/Pod*
    

    At this point git status should show the following modified files (with optional branch.json new 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
    
  5. 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

  1. Manually add RNBranch.xcodeproj

    Right-click on PROJECT_NAME/Libraries and select 'Add files to "PROJECT_NAME"'.

    Add "node_modules/react-native-branch/ios/RNBranch.xcodeproj"

  2. Add libreact-native-branch.a to Linked Frameworks and Libraries.

    Go to PROJECT_NAME > General > Linked Frameworks and Libraries.

    Click +, and add libreact-native-branch.a.

  3. 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/ios and 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

beausmith avatar Aug 01 '18 21:08 beausmith

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.

econner avatar Aug 22 '18 19:08 econner

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

prcbass avatar Aug 28 '18 04:08 prcbass

@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.

csalmi-branch avatar Jan 04 '19 20:01 csalmi-branch

@econner I followed your way, but I am facing issues for running ios app. image

EverestClimber avatar Jul 15 '19 13:07 EverestClimber

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

celineotter avatar Aug 20 '19 22:08 celineotter

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 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.

Hi @econner , I tried your solution that you mentioned. I got two errors:

  1. When I use pod 'Branch-SDK', path: '../node_modules/react-native-branch/ios' in my Podfile, it still throws me the error [!] No podspec found for 'Branch-SDK' in '../node_modules/react-native-branch/ios'.
  2. 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 the RNBranch.xcodeproj to my Libraries list and add $(SRCROOT)/../node_modules/react-native-branch/ios recursively, to the Header Search Paths as stated by @beausmith .

I wonder why this package cannot detect the file within the React dependency in Xcode, thus producing the two errors below: Screen Shot 2020-10-14 at 3 22 39 PM

Do you know how to resolve it @beausmith or @econner ? Your help will be greatly appreciated.

farhankassam2 avatar Oct 18 '20 04:10 farhankassam2

@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 :).

farhankassam2 avatar Oct 18 '20 07:10 farhankassam2

Sorry, I've been out of RN dev for a while. Gonna unsubscribe as I won't have anything useful to add going forward.

beausmith avatar Oct 18 '20 22:10 beausmith