Flutter 词法或预处理器问题 (Xcode):找不到“GoogleMobileAds/GoogleMobileAds.h”文件

问题描述 投票:0回答:1

将 flutter 更新到最新版本后,我不断收到 GoogleMobileAdsGoogleMaps

的错误

当我尝试

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
  • Flutter 版本 3.19.1
  • Dart 版本 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

许多人建议尝试一个新项目,但没有运气,我遇到了同样的问题,我也尝试了谷歌广告存储库中的示例之一,我也遇到了同样的问题...... 我什至尝试从 Codemagic 构建我的应用程序,但我再次遇到同样的问题......

我也尝试过:

  • 使用 2 个软件包的较低版本
  • rm -rf Pods Podfile.lock
  • pod cache clean --all
    以及
    flutter pub cache clean
  • 在 Podfile 中添加 2 个包
  • 分解 Pod 并安装/更新

我已经寻找解决方案两个多星期了,现在这变得非常令人沮丧,请帮助我解决这个问题。下面是我的 podfile 和 pubspec 的依赖项。

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

ios flutter google-maps cocoapods
1个回答
0
投票

发帖希望有一天这可以帮助别人。我最终从我的 MacBook 中完全删除了 pub 缓存和可可豆荚,然后重新安装它们。完成后,我的应用程序再次正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.