集成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>
- 添加AdMob应用ID字段:
- 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
解决建议
移除手动添加的GoogleMobileAds.framework
google_mobile_ads插件会通过CocoaPods自动依赖Google-Mobile-Ads-SDK,手动添加框架会导致重复链接冲突。直接在Xcode中移除已添加的GoogleMobileAds.framework,确保仅通过Pods管理依赖。修正Podfile配置
无需手动添加pod 'Google-Mobile-Ads-SDK',插件会自动处理版本依赖。保留platform :ios, '14.0'即可,执行以下命令重置依赖:flutter clean cd ios pod deintegrate pod install cd .. flutter pub get检查Xcode构建设置
- 打开iOS项目的Runner target,进入Build Settings -> Linking -> Other Linker Flags,删除重复或错误的链接标记。
- 确认Build Settings -> Framework Search Paths中没有手动添加的GoogleMobileAds.framework路径。
验证架构兼容性
将Xcode的Build Settings -> Architectures设置为Standard Architectures (arm64, x86_64),避免架构不匹配导致符号未定义问题。更新插件版本
尝试将google_mobile_ads升级到最新兼容版本,修改pubspec.yaml中的版本号后执行flutter pub get,再重新执行pod安装。
内容的提问来源于stack exchange,提问作者Oussama Ridène
相关产品推荐
相关产品推荐

