React Native iOS构建提示UMReactNativeAdapter/UMModuleRegistryAdapter.h找不到
问题根因
你开启了use_frameworks!全局配置,UMReactNativeAdapter默认按动态库编译,公出头文件的搜索路径没有被正确添加到主项目的编译配置中,同时和RNPermissions等静态依赖库存在编译类型冲突,最终导致头文件找不到。
解决方案
1. 清理缓存并重装依赖
先关闭Xcode,依次执行以下命令清理环境:
rm -rf ~/Library/Developer/Xcode/DerivedData rm -rf ios/Pods ios/Podfile.lock rm -rf node_modules npm install cd ios && pod install --repo-update
2. 修正Podfile配置
调整Podfile的规则,强制UM系列依赖库按静态库编译:
- 将
use_unimodules!的位置移动到use_frameworks!之后、所有React相关pod声明之前 - 在你现有pre_install代码的最上方,补充UM相关库的静态编译配置:
$static_um_pods = ['UMReactNativeAdapter', 'UMCore', 'UMModuleRegistry', 'UMPermissionsInterface'] installer.pod_targets.each do |pod| if $static_um_pods.include?(pod.name) def pod.build_type; Pod::Target::BuildType.static_library end end end
你原有pre_install中关于UMPermissionsInterface、UMReactNativeAdapter的依赖补充逻辑可以保留,和上面的配置不冲突。
3. 手动添加头文件搜索路径
如果完成前两步后仍然报错,打开Xcode进入主target的Build Settings,找到Header Search Paths配置项,添加如下路径并设置为recursive:
"${PODS_ROOT}/Headers/Public/UMReactNativeAdapter"
4. 低版本兼容处理
如果你使用的react-native-unimodules版本低于0.12.0,将AppDelegate.m中的头文件引入写法替换为相对路径引用:
// 替换掉原来的#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h> #import "UMModuleRegistryAdapter.h"
内容的提问来源于stack exchange,提问作者Naoya Nakamura
相关产品推荐
相关产品推荐

