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

Flutter升级后iOS构建报错:GoogleMobileAds/GoogleMaps头文件缺失

Flutter升级3.19.1后iOS构建报错:Google SDK头文件找不到

升级Flutter到3.19.1版本后,执行flutter build ios时持续触发**Lexical or Preprocessor Issue (Xcode)**错误,提示找不到GoogleMobileAds/GoogleMobileAds.h或GoogleMaps/GoogleMaps.h头文件,具体报错取决于pubspec.yaml中引入的依赖包。

报错详情

Lexical or Preprocessor Issue (Xcode): 'GoogleMaps/GoogleMaps.h' file not found /Users/.../.pub-cache/hosted/pub.dev/google_maps_flutter_ios-2.3.1/ios/Classes/GoogleMapPolylineController.h:5:8
Lexical or Preprocessor Issue (Xcode): 'GoogleMobileAds/GoogleMobileAds.h' file not found /Users/.../.pub-cache/hosted/pub.dev/google_mobile_ads-4.0.0/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h:14:8

系统环境

  • macOS: 13.5.1
  • Xcode: 15.2
  • Flutter版本: 3.19.1
  • Dart版本: 3.3.0
  • CocoaPods版本: 1.15.1

Flutter环境检测结果

[✓] Flutter (Channel stable, 3.19.1, on macOS 13.5.1 22G90 darwin-arm64,
    locale en-GR)
[✓] Android toolchain - develop for Android devices (Android SDK version
    34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.86.2)
[✓] Connected device (2 available)
[✓] Network resources

问题复现情况

最初在包含大量依赖的项目中发现该问题,当时使用google_mobile_ads: ^2.3.0。后续在新项目、Google Ads官方示例项目中均能复现相同错误,甚至通过Codemagic构建也无法解决。

已尝试的修复方案

  • 调整google_mobile_ads和google_maps_flutter的版本
  • 执行rm -rf Pods Podfile.lock清理Pod相关文件
  • 执行pod cache clean --all和flutter pub cache clean清理缓存
  • 在Podfile中手动引入这两个包
  • 执行pod deintegrate后重新执行pod install/update

项目配置文件

Podfile

# Uncomment this line to define a global platform for your project
platform :ios, '14.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  pod 'MLKitVision', :podspec => 'MLKitVision.podspec.json'
  pod 'MLKitCommon', :podspec => 'MLKitCommon.podspec.json'

  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  # Ensure pods also use the minimum deployment target set above
  # https://stackoverflow.com/a/64385584/436422
  puts 'Determining pod project minimum deployment target'

  pods_project = installer.pods_project
  deployment_target_key = 'IPHONEOS_DEPLOYMENT_TARGET'
  deployment_targets = pods_project.build_configurations.map{ |config| config.build_settings[deployment_target_key] }
  minimum_deployment_target = deployment_targets.min_by{ |version| Gem::Version.new(version) }

  puts 'Minimal deployment target is ' + minimum_deployment_target
  puts 'Setting each pod deployment target to ' + minimum_deployment_target

  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      #config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings[deployment_target_key] = minimum_deployment_target
    end
  end
end

pubspec.yaml依赖

environment:
  sdk: '>=2.18.4 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_riverpod:

  cupertino_icons: ^1.0.2
  firebase_core: ^2.7.1
  firebase_auth: ^4.6.3
  cloud_firestore: ^4.8.2
  firebase_messaging: ^14.2.6
  firebase_analytics: ^10.1.5
  firebase_crashlytics: ^3.0.16
  connectivity_plus: ^3.0.3
  intl: any
  google_fonts: ^4.0.3
  firebase_storage: ^11.0.16
  google_sign_in: ^6.1.5
  bloc: ^8.1.1
  equatable: ^2.0.5
  flutter_bloc: ^8.1.2
  ...
  google_maps_flutter: ^2.5.3
  geolocator: ^9.0.2
  geocoding: ^2.1.0
  firebase_ui_firestore: ^1.5.6
  google_mobile_ads: 4.0.0

flutter_launcher_icons:
...


dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0
  mockito: ^5.4.2
  build_runner: ^2.4.6

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 22:35:00