Проблема с лексикой Flutter или препроцессором (Xcode): файл GoogleMobileAds/GoogleMobileAds.h не найден

После того, как я обновил Flutter до последней версии, я продолжаю получать эту ошибку для GoogleMobileAds и GoogleMaps.

Когда я пытаюсь flutter build ios, я получаю ту же ошибку 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/GoogleMa pPolylineController.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/Clas ses/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h:14: 8

(В зависимости от того, какой пакет находится в pubspec)

Система

  • macOS: 13.5.1
  • xКод: 15.2
  • Флаттер версия 3.19.1
  • Дартс версия 3.3.0
  • CocoaPods версия 1.15.1
[✓] 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 и получил ту же проблему... Я даже пытался создать свое приложение с помощью Codemagic, и снова у меня возникла та же проблема...

Я также пробовал:

  • играю с более ранними версиями двух пакетов
  • rm -rf Pods Podfile.lock
  • pod cache clean --all вместе с flutter pub cache clean
  • Добавьте 2 пакета в подфайл.
  • деинтеграция модулей и установка/обновление

Я искал решение более двух недель, и это меня очень расстраивает, пожалуйста, помогите мне в этом. Ниже приведен мой подфайл и зависимости моей pubspec.

Подфайл

# 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

Я оставил несколько других пакетов Google на случай, если они могут как-то повлиять на мою проблему, потому что я сталкиваюсь с той же проблемой с картами Google.

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


100
1

Ответ:

Решено

Публикую в надежде, что однажды это кому-нибудь поможет. В итоге я полностью удалил со своего MacBook кэш паба и какао-стручки с устройства, а затем заново установил их. Как только я это сделал, мое приложение снова заработало нормально.