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

Flutter iOS模拟器运行报错:CocoaPods无法找到兼容的GoogleMLKit/MLKitCore版本

解决iOS Flutter项目中GoogleMLKit/MLKitCore版本冲突问题

问题详情

在iOS模拟器执行flutter run时触发CocoaPods依赖冲突:无法找到兼容的GoogleMLKit/MLKitCore版本。具体冲突为:

  • google_mlkit_text_recognition 0.5.0依赖GoogleMLKit/MLKitCore 3.2.0
  • mobile_scanner 2.0.0依赖GoogleMLKit/MLKitCore 2.6.0

已尝试以下操作但未解决:

  • 通过flutter pub outdated更新所有依赖包
  • 使用M1适配命令sudo arch -x86_64 gem install ffi && arch -x86_64 pod install更新Pods
  • iOS目录中未生成Podfile.lock文件

解决方案

1. 对齐第三方包的依赖版本

查看两个冲突包的版本兼容情况:

  • 升级mobile_scanner到支持GoogleMLKit/MLKitCore 3.x的版本(检查其最新版本是否已适配)
  • 或降级google_mlkit_text_recognition到依赖2.6.0的版本(比如0.4.x系列)

修改pubspec.yaml中的对应版本后,执行flutter pub get,再进入iOS目录执行arch -x86_64 pod install。

2. 在Podfile中强制指定统一版本

在iOS目录的Podfile中,target 'Runner'代码块内添加强制版本约束,强制使用3.2.0版本:

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  # 强制指定MLKitCore版本
  pod 'GoogleMLKit/MLKitCore', '3.2.0'

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

保存后执行:

arch -x86_64 pod install

3. 彻底清理缓存后重新构建

执行以下步骤重置依赖:

  • 删除iOS目录下的Pods文件夹
  • 执行flutter clean
  • 执行flutter pub get
  • 进入iOS目录执行arch -x86_64 pod install

4. 检查iOS最低版本要求

部分MLKit版本需要更高的iOS版本支持,可将Podfile中的平台版本升级:

platform :ios, '12.0'

用户提供的配置文件

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  animated_splash_screen: ^1.3.0
  carousel_slider: ^4.1.1
  provider: ^6.0.2
  flutter_otp_text_field: ^1.0.1
  firebase_core: ^2.2.0
  firebase_auth: ^4.1.2
  google_sign_in: ^5.4.0
  mocobaas_pkg: ^0.0.7
  http: ^0.13.1
  flutter_local_notifications: ^12.0.0
  rxdart: ^0.27.4
  webview_flutter: ^3.0.4
  # flutter_share_me: ^1.4.0
  flutter_sms: ^2.3.3
  url_launcher: ^6.1.3
  i18n_extension: ^5.0.0
  percent_indicator: ^4.2.2
  camera: ^0.10.0
  path_provider: ^2.0.11
  image_picker: ^0.8.5+3
  intl: ^0.17.0
  shared_preferences: ^2.0.15
  syncfusion_flutter_signaturepad: ^20.2.39
  pdf: ^3.8.1
  gallery_saver: ^2.3.2
  dio: ^4.0.6
  native_device_orientation: ^1.1.4
  google_mlkit_text_recognition: ^0.5.0
  pinenacl: ^0.5.1
  string_similarity: ^2.0.0
  firebase_messaging: ^14.1.0
  image: ^3.2.0
  exif: ^3.1.2
  mobile_scanner: ^2.0.0
  permission_handler: ^10.2.0
  printing: ^5.9.2
  firebase_dynamic_links: ^5.0.5
  flutter_keyboard_visibility: ^5.3.0
  grouped_list: ^5.1.2
  emoji_picker_flutter: ^1.3.1
  local_auth: ^2.1.2
  flutter_contacts: ^1.1.5
  custom_pin_screen: ^0.3.0
  tutorial_coach_mark: ^1.2.4
  elliptic: ^0.3.8
  ninja: ^3.0.7
  cryptography: ^2.0.5
  jose: ^0.3.2
  flutter_screenutil: ^5.6.0
  google_fonts: ^3.0.1
  janus_client: ^2.2.8
  flutter_webrtc: ^0.9.11
  stop_watch_timer: ^2.0.0

Podfile

# Uncomment this line to define a global platform for your project
platform :ios, '11.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
  use_frameworks!
  use_modular_headers!

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

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 07:15:38