Skip to content

react-native use in Swift ,follow up yoga.h not found . #12294

Closed
@huangcheng1

Description

@huangcheng1

When i use react in swift with cocoapods , found if use_frameworks in podfile, make error : yoga/yoga.h not found .

so i change podfile with :

use_frameworks!

platform :ios, '8.0'

target 'RNSwiftDemo' do

   pod 'React'

end
pre_install do |installer|
   # Yoga exists in two places in the RN source tree. Delete the obsolete one to avoid redefinitions
   `rm -rf ./xxx/React/CSSLayout`
end

post_install do |installer|
   patch_subspecs(installer)
end

def patch_subspecs(installer)
   # patch source and header files
   `find ./xxx/React/React ./xxx/React/ReactCommon ./xxx/React/Libraries \\( -name *.h -o -name *.m -o -name *.mm \\) -print0 | xargs -0 sed -i '' -E 's:<(yoga|jschelpers|cxxreact)/(.*)>:"\\2":g'`
   
   # exclude duplicate symbols
   # https://github.com/facebook/react-native/issues/11502
   installer.pods_project.targets.each do |target|
       next unless target.name == 'React'
       
       source_files = target.source_build_phase.files
       uniqs = source_files.uniq { |f| f.file_ref.path }
       (source_files - uniqs).each { |dup| source_files.delete(dup) }
   end
end

can work on ObjC, but ObjC file must use .mm,

so i guess , cpp cause this problem .

don't work on Swift, even make ObjeC file to middle file.

Description

swift can't use react , cstdint not found
cocopods 1.2.0 use_frameworks
swift 3.0
react-native 0.40.0

Activity

kmuralidharan91

kmuralidharan91 commented on Feb 10, 2017

@kmuralidharan91

facing the same issue in swift 3.0 project.
can u guys help us?

nikolal

nikolal commented on Feb 11, 2017

@nikolal

I also have this issue.

pilwon

pilwon commented on Feb 13, 2017

@pilwon
Contributor

Same problem here. Does someone have any suggestions?

kmuralidharan91

kmuralidharan91 commented on Feb 14, 2017

@kmuralidharan91

Solution from @julienfouilhe

You don't need all the above fixes anymore, remove your patch function in your Podfile, remove the postinstall script in your package.json, just put the master branch of react-native in your dependencies and add yoga as a pod dependency and it should work

package.json:

"react-native": "facebook/react-native#master"
Podfile:

react_path = '../node_modules/react-native'
yoga_path = File.join(react_path, 'ReactCommon/yoga')

pod 'React', :path => react_path, :subspecs => [
'Core',
'RCTText',
'RCTImage',
'RCTWebSocket', # needed for debugging
'RCTNetwork'
]
pod 'Yoga', :path => yoga_path
Don't forget to change all your #include "RCT..." to #include <React/RCT...> too

julienfouilhe

julienfouilhe commented on Feb 14, 2017

@julienfouilhe

See #11781

askielboe

askielboe commented on Feb 15, 2017

@askielboe

Same issue with react-native 0.42.0-rc.3. Using @julienfouilhe's Podspec fixes it for me.

locked as resolved and limited conversation to collaborators on Aug 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @askielboe@pilwon@julienfouilhe@huangcheng1@nikolal

        Issue actions

          react-native use in Swift ,follow up yoga.h not found . · Issue #12294 · facebook/react-native