iOS项目集成Firebase Analytics遇C函数声明弃用错误求助
解决Firebase Analytics中“A function declaration without a prototype is deprecated”错误
问题场景
iOS项目集成Firebase Analytics后,运行时触发编译错误:A function declaration without a prototype is deprecated in all versions of C,错误指向Firebase依赖库中的代码行GDTCORNetworkType GDTCORNetworkTypeMessage() {,执行pod update后问题仍存在,且为纯Xcode原生项目(非React Native)。
错误原因
该错误源于C语言标准变更:C11及更高版本要求函数声明必须明确参数列表(空参数需声明为void),而GDTCORNetworkTypeMessage()采用了旧式的空参数声明方式,在新的编译标准下被标记为废弃。
解决方法
方法1:调整项目C语言编译标准
- 打开项目Target的
Build Settings - 搜索
C Language Dialect,将其设置为GNU99 [-std=gnu99](GNU99标准兼容旧式函数声明) - 重新编译项目
- 打开项目Target的
方法2:针对Firebase依赖单独设置编译选项
在Podfile中添加以下配置,仅对GoogleDataTransport库(错误来源库)设置兼容的编译标准:post_install do |installer| installer.pods_project.targets.each do |target| if target.name == 'GoogleDataTransport' target.build_configurations.each do |config| config.build_settings['CLANG_C_LANGUAGE_STANDARD'] = 'gnu99' end end end end执行
pod install重新安装依赖后编译项目。方法3:指定适配Xcode版本的Firebase版本
若当前Firebase版本与Xcode版本不兼容,可在Podfile中指定稳定兼容版本:pod 'Firebase/Analytics', '~> 10.17.0' # 替换为适配你Xcode版本的最新稳定版执行
pod update Firebase/Analytics更新依赖后编译。
内容的提问来源于stack exchange,提问作者MetaSnarf
相关产品推荐
相关产品推荐

