React Native中无法构建Objective-C模块YogaKit问题求助
问题描述
正在进行macOS桥接开发,启用use_frameworks!并禁用Flipper后,出现「Could not build Objective-C module 'YogaKit'」报错,已尝试删除Podfile.lock、清理重建项目,问题仍未解决。
我的Podfile配置
require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '12.4' prepare_react_native_project! pod 'mailcore2-ios' pod 'GTMOAuth2', :modular_headers => true pod 'GTMAppAuth', :modular_headers => true pod 'YogaKit' flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled use_react_native!(:flipper_configuration => ENV['CI'] ? FlipperConfiguration.disabled : FlipperConfiguration.enabled, # Note: you also can pass extra params #FlipperConfiguration.enabled(['Debug', 'Staging.Debug'], { 'Flipper': '0.174.0' }) ) linkage = ENV['USE_FRAMEWORKS'] if linkage != nil Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! :linkage => linkage.to_sym end target 'Mailcore' do config = use_native_modules! use_frameworks! :linkage => :static $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly', 'CocoaAsyncSocket', 'ComponentKit', 'DoubleConversion', 'glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit', 'CocoaLibEvent', 'openssl-ios-bitcode', 'boost-for-react-native' ] # Flags change depending on the env values. flags = get_default_flags() use_react_native!(:path => config[:reactNativePath], # Hermes is now enabled by default.Disable by setting this flag to false.# Upcoming versions of React Native may rely on get_default_flags(), but # we make it explicit here to aid in the React Native upgrade process. :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], # Enables Flipper.# # Note that if you have use_frameworks!enabled, Flipper will not work and # you should disable the next line.#: flipper_configuration => FlipperConfiguration.disabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) target 'MailcoreTests' do inherit! :complete # Pods for testing end post_install do | installer | react_native_post_install( installer, # Set `mac_catalyst_enabled` to `true` in order to apply patches # necessary for Mac Catalyst builds :mac_catalyst_enabled => false ) installer.pods_project.build_configurations.each do | config | config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" __apply_Xcode_12_5_M1_post_install_workaround(installer) end end end
解决方案
针对「Could not build Objective-C module 'YogaKit'」的问题,可按以下步骤修复:
给YogaKit启用模块化头
替换Podfile中pod 'YogaKit'为:pod 'YogaKit', :modular_headers => true启用
use_frameworks!后,部分依赖需要显式开启模块化头才能被正确识别。移除重复的
use_react_native!调用
你的Podfile存在两次use_react_native!调用,会导致配置冲突。删除外部的那段重复配置,并在target内部的调用中明确禁用Flipper:use_react_native!(:path => config[:reactNativePath], :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], :flipper_configuration => FlipperConfiguration.disabled, :app_path => "#{Pod::Config.instance.installation_root}/.." )清理冗余的静态框架配置
既然已禁用Flipper,从$static_framework数组中移除所有Flipper相关项,简化为:$static_framework = ['DoubleConversion', 'glog', 'Yoga', 'YogaKit', 'boost-for-react-native']重新安装依赖
执行以下命令清理并重新拉取Pod:pod deintegrate rm -rf Podfile.lock pod install检查Xcode项目配置
打开Xcode,前往项目Build Settings,确保Build Libraries for Distribution设置为YES;随后清理项目(Cmd+Shift+K)并重新构建(Cmd+B)。
内容的提问来源于stack exchange,提问作者Neeleshwar Kumar
相关产品推荐
相关产品推荐

