React-Native 升级 0.40 问题

2017-05-14  本文已影响220人  bonoCat

react native 版本升级

iOS reactNative 后出现无法编译的情况,主要的问题是 'Lexical Preprocessor Issue'. React header files not found.

由于之前版本是0.39.0没有问题,升级之后出现问题,所以可以从官方文档找到解决方法,在0.40.0 的更新日志如下:

iOS native headers moved

This change affects all native modules and application code on iOS that refer to react native .h files

After facebook/react-native@e1577df, Native code on iOS must refer to headers out of the react namespace. Previously the following would work:

#import "RCTUtils.h"
But now all headers have been moved:

#import <React/RCTUtils.h>
This means that all iOS native libraries need a major version bump for RN 0.40. We attempt to minimize changes of this magnitude, and we apologize for any inconvenience caused.

从上面可以看出 react native 相关头文件引用方式已经改变,所有原生的引用和相关配置需要修改

使用静态链接库应该如何修改?

podfile文件中的描述

由于reactnative可以使用cocoapod 导入,所以可以通过 React.podspec 来了解相关配置

 Pod::Spec.new do |s|
  s.name                    = "React"
  ...
  s.pod_target_xcconfig     = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++14" }
  ...
  
 s.subspec "Core" do |ss|
    ss.dependency             "Yoga", "#{package["version"]}.React"
    ss.dependency             "React/cxxreact"
    ss.source_files         = "React/**/*.{c,h,m,mm,S}"
    ss.exclude_files        = "**/__tests__/*", "IntegrationTests/*", "React/DevSupport/*", "React/Modules/RCTDev{LoadingView,Menu}.*", "React/**/RCTTVView.*", "ReactCommon/yoga/*", "React/Cxx*/*"
    ss.framework            = "JavaScriptCore"
    ss.libraries            = "stdc++"
  end
  
   s.subspec "cxxreact" do |ss|
    ss.dependency             "React/jschelpers"
    ss.source_files         = "ReactCommon/cxxreact/{JSBundleType,oss-compat-util}.{cpp,h}"
    ss.private_header_files = "ReactCommon/cxxreact/{JSBundleType,oss-compat-util}.h"
    ss.pod_target_xcconfig  = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"" }
  end
  

所需以下库

xcode配置

头文件改变说明了什么?

由于项目之前包含swift,需要动态链接库,所以只能使用静态链接库的方式导入,现在已经更换为 cocoapod 方式导入,更加方便。

上一篇 下一篇

猜你喜欢

热点阅读