【问题标题】:Firebase Xcode linker command error using Firebase Unity SDK使用 Firebase Unity SDK 的 Firebase Xcode 链接器命令错误
【发布时间】:2017-06-13 06:47:31
【问题描述】:

Firebase Unity SDK 1.1.1。 统一 5.5.0p4 XCode 8.2.1

在使用 Firebase 的身份验证和数据库时,在 XCode 中构建项目时出现以下错误:

架构 arm64 的未定义符号:
“_OBJC_CLASS_$_FIRGoogleAuthProvider”,引用自: libAuth.a 中的 objc-class-ref(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
“_OBJC_CLASS_$_FIRGitHubAuthProvider”,引用自: libAuth.a 中的 objc-class-ref(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
“_OBJC_CLASS_$_FIREmailPasswordAuthProvider”,引用自: libAuth.a 中的 objc-class-ref(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
“_OBJC_CLASS_$_FIRFacebookAuthProvider”,引用自: libAuth.a 中的 objc-class-ref(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
“_OBJC_CLASS_$_FIRApp”,引用自: libApp.a 中的 objc-class-ref(app_ios_c76c7d869e568a9b561ea55e25a7dcc0.o)
“_OBJC_CLASS_$_FIRAuth”,引用自: libAuth.a 中的 objc-class-ref(auth_ios_3c64a79cf1eb3f06f9309f4d8e91ee94.o)
“_OBJC_CLASS_$_FIRTwitterAuthProvider”,引用自: libAuth.a 中的 objc-class-ref(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
“_OBJC_CLASS_$_FIROptions”,引用自: libApp.a(app_ios_c76c7d869e568a9b561ea55e25a7dcc0.o) ld 中的 objc-class-ref:符号不是 为架构 arm64 clang 找到:错误:链接器命令失败 退出代码 1(使用 -v 查看调用)

我是否错过了 XCode 中的某些内容?或者有什么要在 Unity 中检查的?

谢谢!

【问题讨论】:

  • 您在使用 Firebase CocoaPod 吗?如果是,你打开项目时是打开.xcodeproj文件还是.xcworkspace文件?
  • 我想我不使用 CocoaPod。它只是使用 Unity 的“构建和运行”。这会生成一个 .xcode 项目,然后打开该项目。并在我的设备上运行 xcode 项目。
  • Unity SDK 3.0.0 和 Unity 版本 Unity 5.5.0f3(从统一云构建服务器编译)有完全相同的链接错误。此版本应该与统一云构建一起使用。旧版本会在构建过程中更早地生成 pod 错误

标签: xcode unity3d firebase firebase-realtime-database firebase-authentication


【解决方案1】:

我花了几天时间试图找出使用 Unity Cloud Build 构建与本地构建的错误。希望这可以帮助其他人!

本地构建

只要您安装了 CocoaPods,它就可以工作。如果未安装 CocoaPods,则在为 iOS 构建后 Unity 控制台中会出现错误。除此之外,Firebase 提供的说明适用于 Unity 5.6 和 Xcode 8.3。

使用 Unity Cloud Build 构建

CocoaPods 在 UCB 上不可用,但 Firebase 有一个非 CocoaPods 替代方案:https://firebase.google.com/docs/ios/setup#frameworks

手动添加框架

这些说明假设是原生 iOS 构建,但您可以简单地将所需的框架拖到 Assets/Plugins/iOS/Firebase 中,而不是拖到 Xcode 项目中。 Unity 会在构建时将这些框架添加到 Xcode 项目中。

添加链接器标志

您需要手动将-ObjC 添加到其他链接标志中。出于某种原因,它出现在我本地的 Xcode 项目中,但在 UCB 进行构建时没有出现。创建一个类似于 maros 提到的后期处理脚本:https://forum.unity3d.com/threads/problem-building-ios-app-with-cloud-build-using-google-analytics.390803/#post-2549911

您需要像这样添加-ObjC

proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");

如果您不添加此部分,UCB 可能仍会创建构建,但游戏会在尝试创建 FirebaseAuth 后立即崩溃,因为它将引用由于缺少 -ObjC 标志而未包含的扩展/类别方法。

添加其他必需的框架和库

根据您使用的 Firebase 功能,您可能需要不同的附加框架或库。例如,我使用了 FirebaseDatabase,虽然文档没有提到这一点,但 Xcode 抱怨链接器错误,需要我添加 libicucore.tbd

我认为解决此问题的最佳方法是在本地卸载 CocoaPods,然后让 Unity 创建 Xcode 项目,这样我就可以更准确地表示 UCB 的体验。这部分可能需要一些试验和错误以及谷歌搜索来确定链接器错误所指的是哪个框架或库。尝试在本地构建 Xcode 项目,如果有的话,你会得到链接器错误。

我补充说:

List<string> frameworks = new List<string>() {
    "AdSupport.framework",
    "CoreData.framework",
    "SystemConfiguration.framework",
    "libz.dylib",
    "libsqlite3.dylib",
    "libicucore.tbd"
};

手动移动 GoogleServices-Info.plist

另一个奇怪的是,UCB 没有将 GoogleServices-Info.plist 移动到 Xcode 项目中。必须有一些其他脚本不在本地运行的 UCB 上运行。在添加链接器标志和框架的后处理脚本中,您还可以将 GoogleServices-Info.plist 移动到 Xcode 项目目录中,然后将其添加到包中。

首先移动文件:

if (!File.Exists(path + "/GoogleService-Info.plist"))
{
    FileUtil.CopyFileOrDirectory ("GoogleService-Info.plist", path + "/GoogleService-Info.plist");
}

然后将其添加到构建中:

string guid = proj.AddFile("GoogleService-Info.plist", "GoogleService-Info.plist");
proj.AddFileToBuild(target, guid);

应该就是这样。如果在添加更多 Firebase 功能时遇到任何其他问题,我会进行更新。目前我正在使用身份验证、数据库和分析。

【讨论】:

    【解决方案2】:

    首先,感谢大家分享您的(辛勤)工作!

    关于这个主题已经说了很多,但我花了 很多 时间和 很多 反复试验来收集关于 SO 和Unity论坛,所以我将发布我最终制定的解决方案,它最终为我解决了所有问题,使用unity cloud build/Unity 5.6.0f3/Xcode 8.0,该项目仅使用firebase分析包

    统一云构建解决方案

    • 从 Unity > Assets > Play Services Resolver > iOS Resolver > Settings 完全禁用 cocoapods(取消选中“Podfile Generation”和“Auto Install Cocoapod Tools in Editor”,选择“None - do not integration Cocoapods”) p
    • 将 GoogleServices-Info.plist 放入 Unity“Assets”文件夹中
    • PostBuildProcessor 方法:

    private static void ProcessPostBuild (BuildTarget buildTarget, string path)
    {
        // Only perform these steps for iOS builds
        #if UNITY_IOS
    
        Debug.Log ("[UNITY_IOS] ProcessPostBuild - Adding Google Analytics frameworks.");
    
        // Go get pbxproj file
        string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
    
        // PBXProject class represents a project build settings file,
        // here is how to read that in.
        PBXProject proj = new PBXProject ();
        proj.ReadFromFile (projPath);
        // This is the Xcode target in the generated project
        string target = proj.TargetGuidByName("Unity-iPhone");
    
        proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
        proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-v");
        proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
    
        if (!File.Exists(path + "/GoogleService-Info.plist"))
        {
            FileUtil.CopyFileOrDirectory("Assets/GoogleService-Info.plist", path + "/GoogleService-Info.plist");
        }
        string guid = proj.AddFile("GoogleService-Info.plist", "GoogleService-Info.plist");
        proj.AddFileToBuild(target, guid);
    
        // List of frameworks that will be added to project
        List<string> frameworks = new List<string>() {
            "AddressBook.framework",
            "AdSupport.framework",
            "CoreData.framework",
            "SystemConfiguration.framework",
        };
    
        // Add each by name
        frameworks.ForEach((framework) => {
            proj.AddFrameworkToProject(target, framework, false);
        });
    
        // List of frameworks that will be added to project
        List<string> usrLibFrameworks = new List<string>() {
            "libsqlite3.tbd",
            "libz.tbd",
            "libicucore.tbd",
        };
    
        // Add each by name
        usrLibFrameworks.ForEach((framework) => {
            proj.AddFileToBuild(target, proj.AddFile("usr/lib/"+ framework, "Frameworks/" + framework, PBXSourceTree.Sdk));
        });
    
    
        // Write PBXProject object back to the file
        proj.WriteToFile (projPath);
    
        #endif
    }
    

    PS 很疯狂,firebase unity sdk 需要这样的 hack 才能工作(UCB 对我们来说是绝对要求,我猜对大多数多平台移动开发人员来说),我希望所有这些变通办法很快就会没用,但判断所有这些问题从官方的 Firebase Unity 支持开始就在这里,我不会太指望它

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,刚刚解决了。

      找到 Podfile 文件并在文本编辑器中打开它。 删除

      , :integrate_targets => 假

      在第二行,所以它说: 安装! 'cocoapods'

      然后在platform后面加一行:ios...

      使用_frameworks!

      然后打开一个终端屏幕并进入该项目的目录。输入“pod install”并输入。 如果一切顺利,将创建一个工作区文件并显示一条消息,您应该在 Xcode 中打开工作区而不是项目。所以关闭xcode中的项目,打开projectname.xcworkspace文件。现在 Xcode 将打开工作区,您将能够运行该项目。您可能需要将部署目标调整为 8.0。 希望这对你有用

      【讨论】:

        【解决方案4】:

        我只是想通了,只要在你的统一创建的 pod 文件中使用旧版本就可以了

        target 'Unity-iPhone' 做 pod 'Firebase/Analytics'、'3.17.0' 吊舱'Firebase/Auth','3.17.0' 吊舱“火力基地/核心”,“3.17.0” pod 'Google-Mobile-Ads-SDK', '7.13' 结束

        ///注意: //

        不要忘记在 (Google-Mobile-Ads-SDK) 的构建设置中将 Enable Modules (c 和 Objective-c) 设置为 yes

        那么 从终端打开文件夹并运行: -> 吊舱安装 更新 pod

        :)

        【讨论】:

        • 不要忘记在 (Google-Mobile-Ads-SDK) 的构建设置中将启用模块(c 和 Objective-c)设置为是
        • 这似乎可以解决问题。一定是最新的firebase sdk的问题
        【解决方案5】:

        使用 Xcode 在本地使用 Firebase 框架构建 Unity 应用:

        这都是关于 iOS SDK 版本的。这个答案有部分解决方案:https://stackoverflow.com/a/41908040/8063631

        在 Mac 环境下工作。

        在 Unity 中构建到 iOS 时。请务必在之前检查: 资产 -> iOS 解析器 -> 设置

        • Cocoapods 集成
          • Xcode 工作区 - 将可可豆荚添加到 Xcode 工作区
        • 在编辑器中自动安装 Cocoapods 工具

        构建到 iOS 并打开 .workspace 文件。

        然后转到 Pods -> Podfile 并添加过去的发布版本(3.7.0),因为 4.0.0 启动该错误。

        target 'Unity-iPhone' do
            pod 'Firebase/Auth'
            pod 'Firebase/Core'
        end
        

        通过(例如...)

        target 'Unity-iPhone' do
            pod 'Firebase/Auth', '3.7.0'
            pod 'Firebase/Core', '3.7.0'
        end
        

        关闭 xCode IDE 以避免冲突,如果您还没有 Cocoapods,请安装它 (https://guides.cocoapods.org/using/getting-started.html):

        检查:

        pod --version
        

        安装方式:

        sudo gem install cocoapods
        

        通过运行终端转到您的项目文件夹并输入:

        pod install
        

        它将删除当前版本并将其替换为 3.7.0

        打开 xCode 并按 Product -> Clean and Product -> Build

        【讨论】:

          【解决方案6】:

          我遇到了同样的问题,花了几个小时后我得到了主要问题。

          这是 podfile 库定义的特定版本。

          target 'Unity-iPhone' do
              pod 'Firebase/Auth', '4.10.0'
              pod 'Firebase/Core', '4.10.0'
          end
          

          当统一构建 iOS 项目的 podfile 时,他们定义了最新的库版本。但是当从 xcode/terminal 尝试从 GIT 更新 pod 库并且特定版本不可用时,它无法更新并显示此错误。

          解决方案很简单,不需要定义具体的版本。 pod 将更新 GIT 的最新版本。

          target 'Unity-iPhone' do
              pod 'Firebase/Auth'
              pod 'Firebase/Core'
          end
          

          【讨论】:

          • 谢谢,这为我解决了。只需删除特定版本即可!
          【解决方案7】:

          CocoaPods

          CocoaPods 是 iOS/macOS 项目的依赖管理器。它用于将外部框架/库安装到您的项目中。


          使用 Xcode 在本地使用 Firebase 框架构建 Unity 应用

          您需要在系统上安装 cocoapods:https://guides.cocoapods.org/using/getting-started.html#toc_3


          在 Unity Build Cloud 上使用 Firebase 框架构建 Unity 应用:

          对于在 Unity Build Cloud 服务器上遇到此问题的用户。

          根据这个论坛帖子:https://forum.unity3d.com/threads/build-failed-cocoapods.421286/ 不支持支持 cocoapods。 (甚至可能还没有计划开发)。

          Cocoapods 负责在您的 Xcode 项目中为您的 iOS 项目设置所有引用的库。由于 Unity Build Cloud 不支持它们,因此您需要手动完成。

          • 确保您已在 macOS 系统上安装 cocoapods:https://guides.cocoapods.org/using/getting-started.html#toc_3

          • 在本地构建您的 Unity 应用程序(不要在云端触发构建)。该构建导出一个 Xcode 项目(应该是可运行的)。此 Xcode 项目包含您需要添加到 Unity 项目的库(框架)。

            • 将所有 *.framework 文件夹从 EXPORTED_XCODE_PROJECT/Frameworks 移动到 YOUR_UNITY_PROJECT/Assets/Plugins/iOS 例如:FirebaseAnalytics.frameworkFirebaseCore.framework

            • Firebase 要求项目中也包含 iOS sqlite 框架。为此,请使用此解决方案: https://forum.unity3d.com/threads/problem-building-ios-app-with-cloud-build-using-google-analytics.390803/#post-2549911 在类PostBuildProcessor中修改方法ProcessPostBuild

              // ObjC - needed for Firebase proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC");

              List<string> frameworks = new List<string>() { "AdSupport.framework", "CoreData.framework", "SystemConfiguration.framework", "libz.dylib", "libsqlite3.dylib", "libApp.a", "libAnalytics.a" };

          保存 Unity 项目,现在 iOS Unity Build Cloud 应该可以工作了

          【讨论】:

            【解决方案8】:

            我遇到了这个问题,并通过更新 pod 安装得到了解决,一种方法是清除本地缓存的副本并重新安装 另一种方法是强制安装来自在线资源

            值得一提的是,构建到IOS是成功的

            构建完成,结果为“成功”

            但安装 pod 时出错

            解决方案一

            在 mac 终端上将目录更改为应包含 Podfile 的已构建文件夹

            执行以下操作

            $ pod repo remove master
            $ pod install --repo-update
            

            从统一重建项目应该自动安装pods

            其他解决方案

            从 GitHub 安装

            查看Firebase pods了解更多信息

            对于从 5.0.0 开始的版本,每个版本的源代码也部署到 CocoaPods 主服务器,并通过标准 CocoaPods Podfile 语法提供。

            这些说明可用于在其他分支、标签或提交处访问 Firebase 存储库。

            背景

            有关覆盖 pod 源位置的说明和选项,请参阅 Podfile 语法参考。

            Source Pod 分步安装说明

            对于 iOS,请将以下行的子集复制到您的 Podfile

            pod 'Firebase' # To enable Firebase module, with `@import Firebase` support pod 'FirebaseCore', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseAuth', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseDatabase', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseFirestore', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseFunctions', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseMessaging', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseStorage', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0'

            对于 macOS 和 tvOS,请复制以下内容的子集: pod 'FirebaseCore', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseAuth', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseDatabase', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0' pod 'FirebaseStorage', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '5.0.0'

            1- 确保您至少拥有 CocoaPods 版本 1.4.0 - pod --version。

            2- 删除您不需要的任何组件的 pod,但必须始终包含 FirebaseCore。

            3- 将代码更新为最新的 Firebase 版本。见release notes

            4- 运行 pod 更新。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2020-02-13
              • 1970-01-01
              相关资源
              最近更新 更多