Flutter iOS模拟器编译报错:Undefined symbols,移除google_mobile_ads后正常
解决google_mobile_ads: ^5.2.0导致iOS模拟器编译链接失败的问题
以下是针对该问题的实用解决步骤:
检查Podfile配置
- 确保Podfile中指定的iOS最低版本不低于11.0(google_mobile_ads 5.x版本要求):
platform :ios, '11.0' - 在
post_install阶段添加适配脚本,解决版本依赖和架构问题:post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) # 统一设置google_mobile_ads的部署版本 if target.name == 'google_mobile_ads' target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' end end end # 针对M系列芯片模拟器排除arm64架构 installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end end
- 确保Podfile中指定的iOS最低版本不低于11.0(google_mobile_ads 5.x版本要求):
清理缓存并重新构建
执行以下命令彻底清理后重新安装依赖:flutter clean rm -rf ios/Pods ios/Podfile.lock flutter pub get cd ios && pod install --repo-update cd .. && flutter run检查Xcode项目链接配置
打开ios/Runner.xcworkspace,进入Runner目标的Build Settings:- 找到
Other Linker Flags,确保包含-ObjC参数(AdMob框架依赖该参数) - 检查
Link Binary With Libraries中是否已添加AdSupport、CoreTelephony、StoreKit系统框架,若没有则手动添加
- 找到
尝试调整包版本
如果以上步骤无效,可以尝试升级google_mobile_ads到最新稳定版,或降级到5.1.0版本,排除版本兼容性问题。
内容的提问来源于stack exchange,提问作者Fahed FBK
相关产品推荐
相关产品推荐

