React Native融合到原生项目,报Could not build module 'yoga'、Could not build module 'React'错误

1.在ReactNative的/node_modules/react-native/ReactCommon/yoga 文件夹中找到“yoga.podspec”文件并打开,将

spec.public_header_files =’yoga/Yoga.h’,’yoga/YGEnums.h’,’yoga/YGMacros.h’

添加到最后(end前面一行)。

2.删掉podfile.lock文件中关于yoga的数据,在命令行中执行pod install;

3.此时可能会报 ‘RCTAnimation/RCTValueAnimatedNode.h’ file not found 错误,将

#import <RCTAnimation/RCTValueAnimatedNode.h>                   

换成 

#import “RCTValueAnimatedNode.h”

4.报#import fishhook/fishhook.h file not found错误,换成

 #import fishhook.h

5.报Could not build module ‘react’错误,解决办法如下:

# 在Podfile中加入

def fix_cplusplus_header_compiler_error

filepath = ‘../node_modules/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h’

contents = []

file = File.open(filepath, ‘r’)

file.each_line do | line |

contents << line

end

file.close if contents[32].include? “&”

contents.insert(26, “#ifdef __cplusplus”)

contents[36] = “#endif”

file = File.open(filepath, ‘w’)

do |f| f.puts(contents)

                end

        end

end

def fix_unused_yoga_headers

            filepath = ‘./Pods/Target Support Files/yoga/yoga-umbrella.h’

            contents = []

                file = File.open(filepath, ‘r’)

                file.each_line  do | line |

                            contents << line

                            end

                file.close

                    if contents[12].include? “Utils.h”

                            contents.delete_at(15) # #import “YGNode.h”

                            contents.delete_at(15) ##import “YGNodePrint.h”    

                             contents.delete_at(15) # #import “Yoga-internal.h”

                             contents.delete_at(12) # #import “Utils.h”

                              file = File.open(filepath, ‘w’)  do |f| f.puts(contents)

                    end

    end

end

def react_native_fix

        fix_cplusplus_header_compiler_error

        fix_unused_yoga_headers

end

post_install do |installer|

react_native_fix

end

    原文作者:々莫等闲々
    原文地址: https://www.jianshu.com/p/5c81b5532c6a
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞