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

集成google_mobile_ads插件后Flutter iOS构建报Undefined Symbols错误

Flutter集成google_mobile_ads后iOS构建链接失败

报错信息

Error (Xcode): Undefined symbols:
Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

未添加该插件时构建正常,将其加入pubspec.yaml后触发上述报错。

环境信息

  • Flutter版本:3.27.1
  • Dart版本:3.5.3
  • CocoaPods版本:1.16.2
  • google_mobile_ads版本:5.2.0
  • iOS目标版本:14.0

已尝试操作

  • 更新Podfile:
    • 添加pod 'Google-Mobile-Ads-SDK', '~> 11.10.0'
    • 设置platform :ios, '14.0'
  • 验证Info.plist:
    • 添加AdMob应用ID字段:
      <key>GADApplicationIdentifier</key>
      <string>ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx</string>
      
  • Xcode框架配置:
    • 将GoogleMobileAds.framework添加到Frameworks, Libraries, and Embedded Content
    • 设置该框架为Embed & Sign
  • 清理重建:
    • 执行flutter clean、flutter pub get、flutter build ios
  • 重新安装CocoaPods:
    • 删除Podfile.lock和Pods/目录
    • 执行pod install --repo-update

解决建议

  1. 移除手动添加的GoogleMobileAds.framework
    google_mobile_ads插件会通过CocoaPods自动依赖Google-Mobile-Ads-SDK,手动添加框架会导致重复链接冲突。直接在Xcode中移除已添加的GoogleMobileAds.framework,确保仅通过Pods管理依赖。

  2. 修正Podfile配置
    无需手动添加pod 'Google-Mobile-Ads-SDK',插件会自动处理版本依赖。保留platform :ios, '14.0'即可,执行以下命令重置依赖:

    flutter clean
    cd ios
    pod deintegrate
    pod install
    cd ..
    flutter pub get
    
  3. 检查Xcode构建设置

    • 打开iOS项目的Runner target,进入Build Settings -> Linking -> Other Linker Flags,删除重复或错误的链接标记。
    • 确认Build Settings -> Framework Search Paths中没有手动添加的GoogleMobileAds.framework路径。
  4. 验证架构兼容性
    将Xcode的Build Settings -> Architectures设置为Standard Architectures (arm64, x86_64),避免架构不匹配导致符号未定义问题。

  5. 更新插件版本
    尝试将google_mobile_ads升级到最新兼容版本,修改pubspec.yaml中的版本号后执行flutter pub get,再重新执行pod安装。


内容的提问来源于stack exchange,提问作者Oussama Ridène

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 04:55:09