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

Flutter iOS应用运行报错:libavcodec.framework库加载失败

解决Flutter iOS运行时libavcodec库加载失败问题

问题背景

编译已成功,但运行Flutter iOS应用时出现动态库加载失败错误,核心问题是libavcodec.framework无法被找到加载。

完整报错堆栈

dyld[16458]: Library not loaded: @rpath/libavcodec.framework/libavcodec
  Referenced from: <3500F5CF-B1D2-30EC-8D7F-1C29BD45D05E> /private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Runner
  Reason: tried: '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/preboot/Cryptexes/OS@rpath/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/System/Library/Frameworks/libavcodec.framework/libavcodec' (errno=2, not in dyld cache)
Library not loaded: @rpath/libavcodec.framework/libavcodec
  Referenced from: <3500F5CF-B1D2-30EC-8D7F-1C29BD45D05E> /private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Runner
  Reason: tried: '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/private/var/containers/Bundle/Application/984D87E5-818C-49A9-9CB5-F0CC3160D2FF/Runner.app/Frameworks/libavcodec.framework/libavcodec' (errno=2), '/usr/lib/swif
dyld config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/usr/lib/libBacktraceRecording.dylib:/usr/lib/libMainThreadChecker.dylib:/usr/lib/libRPAC.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
(lldb) 

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
  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

pubspec.yaml配置

environment:
  sdk: '>=2.18.2 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  cupertino_icons: ^1.0.2
  video_editor: ^1.5.2
  image_picker: ^0.8.6
  helpers: ^1.2.0
  intl: ^0.17.0
  i18n_extension: ^5.0.1
  optimized_cached_image: ^3.0.1
  youtube_player_flutter: ^8.1.1
  flutter_launcher_icons: ^0.11.0
  flutter_lorem: ^2.0.0
  advance_image_picker: ^0.1.7+1
  wechat_assets_picker: ^8.1.4
  lecle_flutter_absolute_path: ^0.0.2+1
  path_provider: ^2.0.11
  video_thumbnail: ^0.5.3
  flutter_document_picker: ^5.1.0
  flutter_login: ^4.1.1
  uuid: ^3.0.6
  flutter_form_builder: ^7.7.0
  form_builder_validators: ^8.4.0
  state_persistence: ^0.1.0
  shared_preferences: ^2.0.15
  firebase_core: ^2.4.0
  firebase_storage: ^11.0.8
  video_compress: ^3.1.2
  connectivity_plus: ^3.0.2
  internet_connection_checker: ^1.0.0+1
  cached_video_player: ^2.0.3
  visibility_detector: ^0.3.3
  firebase_database: ^10.0.7
  firebase_auth: ^4.2.1
  firebase_dynamic_links: ^5.0.9
  cloud_firestore: ^4.2.0
  cloud_functions: ^4.0.6
  cached_network_image: ^3.2.3
  ffmpeg_kit_flutter_min_gpl: ^5.1.0
  video_player: ^2.4.10
  provider: ^6.0.5
  camera: ^0.9.8+1
  share_plus: ^6.3.0
  package_info_plus: ^3.0.2

dependency_overrides:
  ffmpeg_kit_flutter_min_gpl: ^5.1.0-LTS

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0

解决思路

  • 修正FFmpeg Kit依赖版本:你的pubspec.yaml中同时声明了ffmpeg_kit_flutter_min_gpl: ^5.1.0和版本override为^5.1.0-LTS,版本冲突可能导致库缺失。直接移除主依赖中的ffmpeg_kit_flutter_min_gpl: ^5.1.0,只保留override里的版本,执行flutter pub get后重新安装pods。
  • 清理项目缓存并重建:
    1. 执行flutter clean清除Flutter缓存
    2. 进入iOS目录,删除Pods文件夹和Podfile.lock文件
    3. 回到项目根目录执行flutter pub get
    4. 再次进入iOS目录执行pod install
    5. 重新运行应用
  • 检查Xcode构建配置:
    • 打开Xcode项目,选择Runner target,进入Build Settings
    • 确认Framework Search Paths包含$(inherited)和$(PROJECT_DIR)/Pods/FFmpegKitFlutterMinGPL/Frameworks(根据实际pod路径调整)
    • 确认Runpath Search Paths包含@executable_path/Frameworks和@loader_path/Frameworks
  • 排查依赖兼容性:项目中多个视频相关插件(如video_compress、video_editor)可能依赖FFmpeg组件,确认这些插件与你使用的FFmpeg Kit版本兼容,必要时升级或降级插件版本。
  • 切换FFmpeg Kit版本:如果min_gpl版本缺少libavcodec组件,尝试替换为完整版本ffmpeg_kit_flutter: ^5.1.0-LTS,更新pubspec后重新安装依赖。

内容的提问来源于stack exchange,提问作者Stéphane de Luca

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 04:25:16