You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native iOS构建报错:GoogleMaps/GoogleMaps.h文件未找到

解决iOS端「GoogleMaps/GoogleMaps.h file not found in Google-Maps-iOS-Utils」错误

以下是针对该错误的具体解决步骤:

1. 修正Pod依赖配置

你的Podfile存在重复依赖和未明确关联的问题,按以下方式调整:

  • 移除重复的pod 'react-native-google-maps'(它是react-native-maps的别名,无需单独声明)
  • 给Google-Maps-iOS-Utils添加明确的GoogleMaps依赖声明,确保依赖链正确

修改后的相关Pod配置片段:

rn_maps_path = '../node_modules/react-native-maps'
pod 'react-native-maps', path: rn_maps_path
pod 'GoogleMaps'
pod 'Google-Maps-iOS-Utils', :git => 'https://github.com/googlemaps/google-maps-ios-utils', :depends_on => 'GoogleMaps'

2. 适配use_frameworks!与模块化头文件

如果你的项目启用了use_frameworks!,需要确保Google-Maps-iOS-Utils能正确访问GoogleMaps的头文件:

  • 在post_install钩子中添加额外配置,强制为Google-Maps-iOS-Utils开启模块化头文件:
post_install do |installer|
  react_native_post_install(
    installer,
    config[:reactNativePath],
    :mac_catalyst_enabled => false
  )

  # 新增配置:为Google-Maps-iOS-Utils开启模块化头文件
  installer.pods_project.targets.each do |target|
    if target.name == 'Google-Maps-iOS-Utils'
      target.build_configurations.each do |config|
        config.build_settings['CLANG_MODULES_AUTOLINK'] = 'YES'
        config.build_settings['DEFINES_MODULE'] = 'YES'
      end
    end
  end
end

3. 清理缓存并重新构建

执行以下命令彻底清理并重新安装依赖:

# 进入iOS目录
cd ios
# 移除现有Pods和锁文件
rm -rf Pods Podfile.lock
# 解除Pod集成
pod deintegrate
# 重新安装Pods
pod install
# 清理Xcode缓存
xcodebuild clean

完成以上步骤后,重新用Xcode构建项目即可解决头文件找不到的问题。

内容的提问来源于stack exchange,提问作者ChoHJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 01:27:53