Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Cocoapods installs the "React" pod, creating conflicts #621

Closed
hhff opened this issue Mar 8, 2018 · 17 comments
Closed

Using Cocoapods installs the "React" pod, creating conflicts #621

hhff opened this issue Mar 8, 2018 · 17 comments

Comments

@hhff
Copy link

hhff commented Mar 8, 2018

I'm not sure how to best handle this, but my project uses pods, and when I install react-native-svg as a pod, it depends on the React pod, and installs it.

My builds then start failing because there are 2 versions of React declared.

How are folks dealing with this?

Edit: It's similar to this issue: oblador/react-native-vector-icons#303

@msand
Copy link
Collaborator

msand commented Mar 8, 2018

I've been using an ugly hack in the PodFile: invertase/react-native-firebase#414 (comment)

  post_install do |installer_representation|
      installer_representation.pods_project.targets.each do |target|
          if target.name == "React"
              target.remove_from_project
          end
      end
  end

I really wish there was some better way. Please find one for me 😄

@ianoshorty
Copy link

Having the same issue, but the proposed fix above doesn't work for me. If I add it, I end up with missing component errors.

@msand
Copy link
Collaborator

msand commented Mar 9, 2018

You'll also need to link react-native manually, by adding the projects to libraries in your main project, and to your "Linked Frameworks and Libraries" in the Build Phases. Such that you have it linked both manually and using cocoapods, and then add the hack to remove the cocoapods one, such that you're able to archive your project.
facebook/react-native#15838 (comment)

@ianoshorty
Copy link

Thanks for the tip @msand - fixed for me! This definitely needs a less "hacky" fix.

@msand
Copy link
Collaborator

msand commented Mar 10, 2018

Great, happy I could help. I managed to get a slightly less hacky version working today. Removed the manually linked version, but then building/running/archiving from XCode breaks. But I found that compiling manually from the cli still works, so I added two npm scripts to package.json
msand/SVGPodTest@5343af5#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R8

+    "release": "cd ios && xcodebuild -workspace SVGPodTest.xcworkspace -configuration Release -scheme SVGPodTest -destination id=711F49EC-5747-4393-94DB-77B97D466541 -derivedDataPath build",
+    "archive": "cd ios && xcodebuild -workspace SVGPodTest.xcworkspace -configuration Release -scheme SVGPodTest -derivedDataPath build  -archivePath ./YourApp.xcarchive archive"

It would be nice to be able to build from XCode as well. Not sure how its possible that it works from the cli but is broken there.

@jgresham
Copy link

jgresham commented Mar 24, 2018

Having this issues as well. Currently, is the best solution to just to not use Cocoapods? Thanks

@msand
Copy link
Collaborator

msand commented Mar 24, 2018

Another approach I found is to remove all the manually linked libraries and let cocoapods link React as well. This doesn't allow starting debug mode from xcode though, but works with run-ios in the cli. If you need to debug the obj-c code, I recommend duplicating the target which you're installing the pods in to, and manually link react there. If you can, I would recommend avoiding cocoapods, as it's just another thing which can break in your system. If npm, react-native link and normal xcode works for you, then just use that. If you need something from outside npm, like with react-native-fbsdk (or want swift code, I think) etc., then you need cocoapods at least.

@petrogad
Copy link

petrogad commented Jun 1, 2018

I'm with @jgresham is the best solution to just avoid Cocopods? This is super frustrating that causes duplicate compilations.

@skurfuerst
Copy link

Hey everybody,

I've investigated the installation of React Native dependencies a little more in-depth; and I've come to a quite clean cocoapod-based solution (I hope). I've summed up the approach in a blog post at https://sandstorm.de/de/blog/post/react-native-managing-native-dependencies-using-xcode-and-cocoapods.html .

Maybe it helps somebody :)

All the best,
Sebastian

@roycedot
Copy link

roycedot commented Aug 24, 2018

Hello,

My setup is finally working (before app would crash on start when run or archived from Xcode). Running 'yarn ios' was working fine.

I followed the steps outlined by @msand

  1. I have the React .xcodeproj files added to Libraries of my main Xcode project
  2. libReact.a and libRCTWebSocket.a in "Linked Frameworks and Libraries" on General tab and "Link Binary With Libraries" on Build Phases tab
  3. Podfile "postinstall" hack

But, I also had to

  1. edit Other Linker Flags in my main Xcode Build Settings as the $(inherited) portion was still referencing the React framework from Pods.

Otherwise, linking fails.

  1. Edit [CP] Embed Pods Frameworks in Build Phases on my main Xcode project to remove React from Input Files and Output Files

  2. And you may need to edit ios/Pods/Target Support Files/Pods-(your proj)-frameworks.sh to remove React from the install_framework calls at the bottom. I didn't have to do this last step on a clean project. But did have to on a project where I applied the Podfile fix after trying a bunch of different other stuff.

@saggiyogesh
Copy link

Fixed conflicts with these changes in Podfile

pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge',
    'DevSupport',
    # the following ones are the ones taken from "Libraries" in Xcode:
    'RCTAnimation',
    'RCTActionSheet',
    'RCTBlob',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket'
  ]
  
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/GLog.podspec'
  

pod 'RNSVG', :path => '../node_modules/react-native-svg'

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        if target.name == "React"
            target.remove_from_project
        end
    end
end

@rjruizes
Copy link

rjruizes commented Oct 3, 2018

As @roycedot mentioned above, I had to edit Build Settings -> Other Linker Flags.

I removed $(inherited), which was including -framework "React" and other frameworks. I added back the other frameworks:-framework "yoga" -framework "glog" -framework "folly" -framework "DoubleConversion"

After that I got a successful build and a working debug menu.

@msand
Copy link
Collaborator

msand commented Oct 13, 2018

Has anyone tried removing this line?
https://github.com/react-native-community/react-native-svg/blob/d5a5e97b38e7f3e5b463fe63d3f7b2a2de1f3f14/RNSVG.podspec#L16
I'm thinking perhaps it would still build correctly without it, and perhaps resolve the conflicts. I don't have any cocoapods setup to test with easily right now. Could someone here test it?

@jer-sen
Copy link

jer-sen commented Oct 19, 2018

@msand thanks for your workaround ! I had to add yoga to make it work, cf facebook/react-native#20492 (comment)

@skurfuerst thanks for your great blog post, you should update it adding yoga !

@brianfoody
Copy link

@roycedot sorry a few months later asking you this but could you provide a snippet of how you implemented point (2) above?

Edit [CP] Embed Pods Frameworks in Build Phases on my main Xcode project to remove React from Input Files and Output Files

@chrisheninger
Copy link

Came across this thread debugging a separate issue– but I recently ran into this same problem and wanted to share in case it helps others.

It's a known issue that CocoaPods + React-Native is a current pain point. If you do a search in this thread for "cocoapods"– you'll see there's a lot of good discussion:

react-native-community/discussions-and-proposals#104

tl;dr– Comment by Facebook: We are currently working on recommending CocoaPods by default for iOS projects and with it we are looking to simplify link to cause fewer problems for people.

If you notice that the react@0.11.0 pod is being installed when you run pod install– you'll want to update your podfile to include React and it's dependencies– in the end your podfile should look similar to this:

https://facebook.github.io/react-native/docs/integration-with-existing-apps#configuring-cocoapods-dependencies

@tap349
Copy link

tap349 commented Jun 11, 2019

Came across this thread debugging a separate issue– but I recently ran into this same problem and wanted to share in case it helps others.

It's a known issue that CocoaPods + React-Native is a current pain point. If you do a search in this thread for "cocoapods"– you'll see there's a lot of good discussion:

react-native-community/discussions-and-proposals#104

tl;dr– Comment by Facebook: We are currently working on recommending CocoaPods by default for iOS projects and with it we are looking to simplify link to cause fewer problems for people.

If you notice that the react@0.11.0 pod is being installed when you run pod install– you'll want to update your podfile to include React and it's dependencies– in the end your podfile should look similar to this:

https://facebook.github.io/react-native/docs/integration-with-existing-apps#configuring-cocoapods-dependencies

I just want to add that it might be necessary to remove React pod from ios/Pods/ directory manually to get rid of naming collision - pod install doesn't remove unused pods:

$ rm -rf ios/Pods/React

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests