惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

O
OpenAI News
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
爱范儿
爱范儿
B
Blog
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
V
Visual Studio Blog
P
Proofpoint News Feed
小众软件
小众软件
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - 聂微东
WordPress大学
WordPress大学
博客园 - 【当耐特】
腾讯CDC
T
Tailwind CSS Blog
The Register - Security
The Register - Security
V
V2EX
S
SegmentFault 最新的问题
IT之家
IT之家
D
Docker
I
InfoQ
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
The Cloudflare Blog
量子位
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
美团技术团队
B
Blog RSS Feed

博客园 - Lemo_wd

flutter —— iOS 的构建与分发 wireguard 入门 k3s 基础 —— 将 traefik 替换为 ingress-nginx Pr 入门 为什么 TCP 是3次握手4次挥手? 给 ssh 私钥文件配置统一口令 滚动部署零碎笔记1 Clickhouse 物化视图与投影 Clickhouse 主键索引 Clickhouse 核心概念 ClickHouse 案例学习 —— 使用 ClickHouse 探索 GitHub 统计信息 linux Tun/Tap 虚拟网卡 Clickhouse 的 kafka Engine 集成 Clickhouse 表引擎 —— MergeTree 局域网中的设备间的流量转发 d3.js 构建股权架构图并绘制双向节点树 final cut pro 入门 d3.js 构建股权架构图并绘制股权百分比 flutter 的滚动控制 —— 滚动类组件的内部与整体滚动
flutter —— 理解 iOS 的依赖管理
Lemo_wd · 2026-03-06 · via 博客园 - Lemo_wd

下载依赖

可以通过以下命令生成 iOS 配置文件:

flutter build ios --config-only

等价于传统的方式:

flutter pub get
cd ios
pod install

pod install 做了什么?

  1. 执行 ios/Podfile(本质是一个 Ruby 脚本)。
  2. Podfile 会引入 Flutter SDK 目录下的 packages/flutter_tools/bin/podhelper.rb,并调用:
    • flutter_install_all_ios_pods 方法
    • flutter_install_plugin_pods 方法
      最终生成 Pod 注册信息与符号链接 ios/.symlinks/plugins(指向用户目录下的 .pub-cache)。
  3. 根据 Pod 注册信息找到对应的 .podspec 文件。
  4. 生成 Pods/ 目录,包含 Xcode Target 和构建设置,更新 Podfile.lock,完成依赖安装。

PS:CocoaPods 的“安装”只是准备源码和 Xcode Target,方便后续编译,并不生成独立的二进制文件。

PS: android 是通过 android/settings.gradle 文件中引入的 dev.flutter.flutter-plugin-loader,自动扫描项目根目录的 .flutter-plugins-dependencies 实现的相关依赖的下载。


podhelper.rb 核心源码说明

flutter_install_plugin_pods 方法流程如下:

def flutter_install_plugin_pods(application_path = nil, relative_symlink_dir, platform)
  # 获取项目路径
  application_path ||= File.dirname(defined_in_file.realpath) if respond_to?(:defined_in_file)
  raise 'Could not find application path' unless application_path

  # 准备 symlinks 目录,避免 Podfile.lock 出现开发者绝对路径
  symlink_dir = File.expand_path(relative_symlink_dir, application_path)
  system('rm', '-rf', symlink_dir)
  symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
  system('mkdir', '-p', symlink_plugins_dir)

  # 读取插件依赖信息
  plugins_file = File.join(application_path, '..', '.flutter-plugins-dependencies')
  dependencies_hash = flutter_parse_plugins_file(plugins_file)
  plugin_pods = flutter_get_plugins_list(dependencies_hash, platform)
  swift_package_manager_enabled = flutter_get_swift_package_manager_enabled(dependencies_hash, platform)

  plugin_pods.each do |plugin_hash|
    plugin_name = plugin_hash['name']
    plugin_path = plugin_hash['path']
    has_native_build = plugin_hash.fetch('native_build', true)

    # 判断 iOS/macOS 共享代码路径
    shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false)
    platform_directory = shared_darwin_source ? 'darwin' : platform
    next unless plugin_name && plugin_path && has_native_build

    # 在 .symlinks/plugins 下生成符号链接
    symlink = File.join(symlink_plugins_dir, plugin_name)
    File.symlink(plugin_path, symlink)
    relative = flutter_relative_path_from_podfile(symlink)

    # Swift Package Manager 情况处理
    swift_package_exists = File.exist?(File.join(relative, platform_directory, plugin_name, "Package.swift"))
    next if swift_package_manager_enabled && swift_package_exists

    # 如果插件只支持 SPM 而不支持 CocoaPods,则跳过
    next if swift_package_exists && !File.exist?(File.join(relative, platform_directory, plugin_name + ".podspec"))

    # 注册 Pod 信息,CocoaPods 会根据这个解析 .podspec 并生成 Pods/
    pod plugin_name, path: File.join(relative, platform_directory)
  end
end

核心要点总结

  • .symlinks/plugins 用于统一管理插件路径,保证 Podfile.lock 中使用相对路径。
  • 支持 iOS 和 macOS 的共享代码(darwin 目录)。
  • 对 Swift Package Manager 插件做了跳过处理,避免冲突。
  • 最终由 CocoaPods 根据注册信息解析 .podspec 并生成 Pods/ 目录。