美文网首页
原生项目嵌入React-Native遇到的坑

原生项目嵌入React-Native遇到的坑

作者: 猎手Andy | 来源:发表于2020-01-14 12:44 被阅读0次

    [!] The name of the given podspec Yoga doesn't match the expected one yoga

    分析过程

    查看Podfile中引用关系
    pod "yoga", :path => "../node_modules/react-native/ReactCommon/yoga"

    根据错误字面意思是弄错了的podspec的文件名。因此

    ls ../node_modules/react-native/ReactCommon/yoga/
    Android.mk  BUCK        Yoga.podspec    yoga
    

    发现果然podspec的文件名是Yoga

    解决方法

    修改Podfile引用(大写):

    pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"

    [!] CocoaPods could not find compatible versions for pod "React/Core":

      pod 'React', :path => '../node_modules/react-native', :subspecs => [
        'Core',
        'CxxBridge', # Include this for RN >= 0.47
        'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
        'RCTText',
        'RCTNetwork',
        'RCTWebSocket', # needed for debugging
        # Add any other subspecs you want to use in your project
      ]
    

    解决方法

    使用了老的引用方式,升级到RN0.60以上引用方式发生变化
    参考

    
      pod 'React', :path => '../node_modules/react-native/'
      pod 'React-Core', :path => '../node_modules/react-native/'
      pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
      pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
      pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
      pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
      pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
      pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
      pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
      pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
      pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
      pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
      pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
      pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
      pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
      pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
      pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
      pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
    
      # Explicitly include Yoga if you are using RN >= 0.42.0
      pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
    
      # Third party deps podspec link
      pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
      pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
      pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
    

    官方有个Podfile参考, 但是不太好使:
    https://github.com/facebook/react-native/blob/v0.60.0/template/ios/Podfile

    Unhandled JS Exception: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary.

    令人崩溃的错误 最后找到 https://github.com/facebook/react-native/issues/26614

    https://github.com/facebook/react-native/commit/8131b7bb7b4794e0e7003a6e3d34e1ebe4b8b9bc#diff-a3c6c8e64fbbd1efef345c45e3811571

    参考 Podfile

    
    source 'https://github.com/CocoaPods/Specs.git'
    # Uncomment the next line to define a global platform for your project
    platform :ios, '9.0'
    
    target 'HelloReactNative' do
      # Comment the next line if you don't want to use dynamic frameworks
      # Required for Swift apps
      use_frameworks!
    
      # Your 'node_modules' directory is probably in the root of your project,
    
      #https://github.com/facebook/react-native/blob/v0.60.0/template/ios/Podfile
    
      pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
      pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
      pod 'React', :path => '../node_modules/react-native/'
      pod 'React-Core', :path => '../node_modules/react-native/'
      pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
      pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
      pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
      pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
      pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
      pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
      pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
      pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
      pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
      pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
      pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
      pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
      pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
      pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
      pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
      pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
      pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
      pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
      pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
      pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
      pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
    
      # Explicitly include Yoga if you are using RN >= 0.42.0
      pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
    
      # Third party deps podspec link
      pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
      pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
      pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
    
    end
    
    

    相关文章

      网友评论

          本文标题:原生项目嵌入React-Native遇到的坑

          本文链接:https://www.haomeiwen.com/subject/znaoactx.html