Swift项目通过CocoaPods集成google_mobile_ads SDK后报错
解决Google Mobile Ads SDK v11.6.0集成后的链接错误
在Swift项目中集成google_mobile_ads SDK v11.6.0后,运行时出现如下链接错误,移除SDK后项目可正常运行:
ld: warning: Could not find or use auto-linked library 'swiftXPC': library 'swiftXPC' not found ld: warning: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found ld: warning: Could not find or use auto-linked framework 'MarketplaceKit': framework 'MarketplaceKit' not found ld: Undefined symbols: enum case for MarketplaceKit.AppDistributor.testFlight(MarketplaceKit.AppDistributor.Type) -> MarketplaceKit.AppDistributor, referenced from: l007 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) l008 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) enum case for MarketplaceKit.AppDistributor.marketplace(MarketplaceKit.AppDistributor.Type) -> (Swift.String) -> MarketplaceKit.AppDistributor, referenced from: l007 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) l008 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) enum case for MarketplaceKit.AppDistributor.other(MarketplaceKit.AppDistributor.Type) -> MarketplaceKit.AppDistributor, referenced from: l007 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) l008 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) static MarketplaceKit.AppDistributor.current.getter : MarketplaceKit.AppDistributor, referenced from: function signature specialization <Arg[0] = Dead> of static GoogleMobileAds.GADMarketplaceKitSignals.appDistributor() async -> Swift.String in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) async function pointer to static MarketplaceKit.AppDistributor.current.getter : MarketplaceKit.AppDistributor, referenced from: function signature specialization <Arg[0] = Dead> of static GoogleMobileAds.GADMarketplaceKitSignals.appDistributor() async -> Swift.String in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) enum case for MarketplaceKit.AppDistributor.appStore(MarketplaceKit.AppDistributor.Type) -> MarketplaceKit.AppDistributor, referenced from: l007 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) l008 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) type metadata accessor for MarketplaceKit.AppDistributor, referenced from: l007 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) l008 in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) nominal type descriptor for MarketplaceKit.AppDistributor, referenced from: _symbolic _____Sg 14MarketplaceKit14AppDistributorO in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) __swift_FORCE_LOAD_$_swiftXPC, referenced from: __swift_FORCE_LOAD_$_swiftXPC_$_GoogleMobileAds in GoogleMobileAds[arm64][423](GADMarketplaceKitSignals.o) clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决步骤:
- 检查Xcode版本兼容性:Google Mobile Ads SDK v11.6.0要求Xcode 15.0及以上版本,确保你的Xcode版本符合要求,版本过低则升级Xcode。
- 配置链接器忽略私有依赖:
- 打开项目Target的
Build Settings,找到Other Linker Flags - 添加以下参数:
-weak_framework MarketplaceKit-weak-lswiftXPC
该配置会让链接器忽略这些私有框架/库的缺失,避免报错。
- 打开项目Target的
- 手动添加公开框架:在项目Target的
Build Phases->Link Binary With Libraries中,点击+号,搜索并添加CoreAudioTypes.framework。 - 清理并重新构建:
- 使用
Cmd+Shift+K清理项目 - 前往
Window->Organizer,选中当前项目,点击Delete Derived Data删除缓存 - 重新执行
Cmd+B构建项目
- 使用
- 重新同步SDK依赖:如果使用CocoaPods集成,执行以下命令重新安装依赖:
若手动集成SDK,检查下载的SDK包是否完整,重新替换完整的SDK文件。pod deintegrate pod install
内容的提问来源于stack exchange,提问作者user9792850
相关产品推荐
相关产品推荐

