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

如何修改CocoaPods依赖解决Firebase与GoogleSignIn的版本冲突?

解决方案

方案一:修改Google Sign In的Pod依赖版本(兼容Firebase)

既然你不在意iOS端Google Sign In功能是否可用,可通过强制指定GTMSessionFetcher/Core的版本来解决依赖冲突:

  • 找到Unity项目中Google Sign In插件生成的Podfile模板(一般在Assets/GoogleSignIn/Editor/iOS目录下),手动修改依赖配置:

    • 若模板中有pod 'GoogleSignIn',将其替换为pod 'GoogleSignIn', '~> 6.2'(该版本依赖GTMSessionFetcher/Core ≥2.1,可适配最新Firebase);
    • 或者直接在Podfile末尾添加一行:pod 'GTMSessionFetcher/Core', '>=2.1',强制覆盖低版本依赖。
  • 如果Unity插件会自动生成Podfile(覆盖手动修改),可编写PostProcessBuild脚本在Build后自动修改Podfile:

    using UnityEditor;
    using UnityEditor.Callbacks;
    using System.IO;
    
    public class PodfileModifier
    {
        [PostProcessBuild(999)]
        public static void PostProcessiOSBuild(BuildTarget target, string buildPath)
        {
            if (target != BuildTarget.iOS) return;
    
            string podfilePath = Path.Combine(buildPath, "Podfile");
            if (!File.Exists(podfilePath)) return;
    
            string podContent = File.ReadAllText(podfilePath);
            // 强制添加高版本依赖
            podContent += "\npod 'GTMSessionFetcher/Core', '>=2.1'\n";
            File.WriteAllText(podfilePath, podContent);
        }
    }
    

    将此脚本放在Assets/Editor目录下,Build iOS项目时会自动修改Podfile。

方案二:彻底移除iOS端Google Sign In插件内容(避免冲突)

手动删除文件导致Xcode报错,是因为Unity仍残留了对iOS文件的引用,正确的移除方式如下:

  1. 在Unity中隔离iOS文件
    选中Google Sign In插件下的iOS相关文件(如Assets/GoogleSignIn/iOS下所有文件),在Inspector面板的「Platform Settings」中,取消勾选iOS平台,勾选「Exclude Platform」。这样Build时Unity不会将这些文件打包到iOS项目中,同时保留Android端的文件。

  2. 清理缓存与重建

    • 删除Unity项目根目录下的Library和obj文件夹,重启Unity;
    • 重新生成iOS项目,避免缓存的引用导致报错。
  3. 修复Xcode项目残留引用
    如果仍出现「Build input file cannot be found」错误,打开生成的Xcode项目:

    • 进入「Build Phases」→「Compile Sources」和「Link Binary With Libraries」,移除所有标注为红色的Google Sign In相关文件/框架;
    • 检查「Build Settings」→「Other Linker Flags」,删除任何与Google Sign In相关的标志(如-framework GoogleSignIn)。
  4. 确保代码隔离
    确认所有Google Sign In的代码(包括初始化、命名空间引用等)都被#if !UNITY_IOS包裹,避免iOS编译阶段尝试引用不存在的库:

    #if !UNITY_IOS
    using GoogleSignIn;
    
    public class AuthManager : MonoBehaviour
    {
        void Start()
        {
            GoogleSignIn.Configuration = new GoogleSignInConfiguration
            {
                WebClientId = "your-web-client-id"
            };
        }
    }
    #endif
    

内容的提问来源于stack exchange,提问作者Doruk Okbay

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 03:27:25