Firebase Xcode linker command error using Firebase

2019-01-18 23:50发布

Firebase Unity SDK 1.1.1. Unity 5.5.0p4 XCode 8.2.1

When using Authentication and Database from Firebase I get the following error when building the project in XCode :

Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_FIRGoogleAuthProvider", referenced from: objc-class-ref in libAuth.a(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
"_OBJC_CLASS_$_FIRGitHubAuthProvider", referenced from: objc-class-ref in libAuth.a(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
"_OBJC_CLASS_$_FIREmailPasswordAuthProvider", referenced from: objc-class-ref in libAuth.a(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
"_OBJC_CLASS_$_FIRFacebookAuthProvider", referenced from: objc-class-ref in libAuth.a(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
"_OBJC_CLASS_$_FIRApp", referenced from: objc-class-ref in libApp.a(app_ios_c76c7d869e568a9b561ea55e25a7dcc0.o)
"_OBJC_CLASS_$_FIRAuth", referenced from: objc-class-ref in libAuth.a(auth_ios_3c64a79cf1eb3f06f9309f4d8e91ee94.o)
"_OBJC_CLASS_$_FIRTwitterAuthProvider", referenced from: objc-class-ref in libAuth.a(credential_ios_ef8c3cf45c3329a5e5902f99026c639a.o)
"_OBJC_CLASS_$_FIROptions", referenced from: objc-class-ref in libApp.a(app_ios_c76c7d869e568a9b561ea55e25a7dcc0.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Do I miss something in XCode? Or have something to check in Unity?

Thanks!

8条回答
萌系小妹纸
2楼-- · 2019-01-19 00:02

I spent a couple of days trying to figure out the errors from building with Unity Cloud Build vs building locally. Hopefully this can help someone else!

Building Locally

This just worked as long as you have CocoaPods installed. An error will appear in the Unity console after building for iOS if CocoaPods is not installed. Other than that, the instructions provided by Firebase worked fine with Unity 5.6 and Xcode 8.3.

Building with Unity Cloud Build

CocoaPods is not available on UCB but Firebase has a non-CocoaPods alternative: https://firebase.google.com/docs/ios/setup#frameworks

Add Frameworks Manually

The instructions are assuming a native iOS build but you can simply drag the frameworks you need into Assets/Plugins/iOS/Firebase instead of into an Xcode project. Unity will add those frameworks to the Xcode project on build.

Add Linker Flag

You will need to manually add -ObjC into Other Link Flags. For some reason it showed up in my local Xcode project but not when UCB made the build. Create a post process script much like maros mentioned: https://forum.unity3d.com/threads/problem-building-ios-app-with-cloud-build-using-google-analytics.390803/#post-2549911

You will need to add -ObjC like this:

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

If you do not add this part, UCB may still create a build but the game will crash immediately after trying to create FirebaseAuth as it will reference an extension/category method that was not included due to the missing -ObjC flag.

Add Other Required Frameworks and Libraries

Depending on which Firebase features you are using, you may need different additional frameworks or libs. For example I had used FirebaseDatabase and while the docs did not mention this, Xcode complained about a linker error that required me to add libicucore.tbd.

The best way I could think to solve this was uninstall CocoaPods locally and then have Unity create the Xcode project so that I could get a more accurate representation of what UCB would experience. This part may take some trial and error as well as Googling to figure out which framework or lib the linker error is referring to. Just try to build the Xcode project locally and you will get the linker errors if any.

I added:

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

Manually Move GoogleServices-Info.plist

Another oddity is that UCB did not move the GoogleServices-Info.plist into the Xcode project. There must be some other script that is not running on UCB that does run locally. In the post process script where you add the linker flag and frameworks, you can also move the GoogleServices-Info.plist into the Xcode project directory and then add it to the bundle.

First move the file:

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

Then add it to the build:

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

And that should be it. I will update if I run into any other issues as I add more Firebase features. Currently I am using Auth, Database, and Analytics.

查看更多
仙女界的扛把子
3楼-- · 2019-01-19 00:04

I just figure it out , just use older version in your pod file created by unity to be like this

target 'Unity-iPhone' do pod 'Firebase/Analytics', '3.17.0' pod 'Firebase/Auth', '3.17.0' pod 'Firebase/Core', '3.17.0' pod 'Google-Mobile-Ads-SDK', '7.13' end

///note: //

Don't forgot to set the Enable Modules (c and Objective-c) to yes in building setting for (Google-Mobile-Ads-SDK)

then open folder from terminal and run: ->pod install to update pods

:)

查看更多
仙女界的扛把子
4楼-- · 2019-01-19 00:11

i had this issue and was fixed by updating the pods installation one way was clearing the locally cached copy and reinstall it again and another way was to force the installation to be from an online source

it worth mention that the building to IOS was succeeded

Build completed with a result of 'Succeeded'

but had an error installing the pods

Solution one

on the mac terminal change directory to the builded folder that should contain a Podfile

executed the following

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

Rebuild the project from unity should install the pods automatically

Other solution

Installing from GitHub

see Firebase pods for more information

For releases starting with 5.0.0, the source for each release is also deployed to CocoaPods master and available via standard CocoaPods Podfile syntax.

These instructions can be used to access the Firebase repo at other branches, tags, or commits.

Background

See the Podfile Syntax Reference for instructions and options about overriding pod source locations.

Step-by-step Source Pod Installation Instructions

For iOS, copy a subset of the following lines to your 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'

For macOS and tvOS, copy a subset of the following: 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- Make sure you have at least CocoaPods version 1.4.0 - pod --version.

2- Delete pods for any components you don't need, except FirebaseCore must always be included.

3- Update the tags to the latest Firebase release. See the release notes

4- Run pod update.

查看更多
等我变得足够好
5楼-- · 2019-01-19 00:15

Building Unity app with Firebase framework locally with Xcode:

It is all about the iOS SDK version. This answer have part of the solution: https://stackoverflow.com/a/41908040/8063631

Working on Mac environment.

When build in Unity to iOS. Be sure checked before: Assets -> iOS Resolver -> Setting

  • Cocoapods Integration
    • Xcode Workspace - Add cocoa pods to the Xcode Workspace
  • Auto install Cocoapods Tools in Editor

Build to iOS and open .workspace file.

Then go to Pods -> Podfile and add the past release version (3.7.0), because the 4.0.0 launch that error.

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

by (for example...)

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

Close xCode IDE to avoid conflicts, then install Cocoapods if you don't have it yet (https://guides.cocoapods.org/using/getting-started.html):

Check with:

pod --version

Install with:

sudo gem install cocoapods

Go to your project folder by running Terminal and type:

pod install

It will remove the current versión and it replace it by the 3.7.0

Open xCode and press Product -> Clean and Product -> Build

查看更多
Emotional °昔
6楼-- · 2019-01-19 00:17

CocoaPods

CocoaPods is a dependency manager for iOS/macOS projects. It is used for installing external frameworks/libraries to your project.


Building Unity app with Firebase framework locally with Xcode:

You need to have cocoapods installed on your system: https://guides.cocoapods.org/using/getting-started.html#toc_3


Building Unity app with Firebase framework on Unity Build Cloud:

For the users who experience this issue on Unity Build Cloud server.

According to this forum thread: https://forum.unity3d.com/threads/build-failed-cocoapods.421286/ supporting cocoapods is not supported. (and probably not even scheduled for development).

Cocoapods are responsible for having all referenced libraries for your iOS project setup in your Xcode project. As they are not supported on Unity Build Cloud, you need to do it manually.

  • make sure you have installed cocoapods on your macOS system: https://guides.cocoapods.org/using/getting-started.html#toc_3

  • build your Unity app locally (don't trigger the build on the cloud). The build exports an Xcode project (which should be runnable). This Xcode project contains libraries (Frameworks) you need to add to the Unity project.

    • move all the *.framework folders from EXPORTED_XCODE_PROJECT/Frameworks to YOUR_UNITY_PROJECT/Assets/Plugins/iOS e.g.: FirebaseAnalytics.framework, FirebaseCore.framework

    • Firebase requires iOS sqlite framework to be also included in the project. For that use this solution: https://forum.unity3d.com/threads/problem-building-ios-app-with-cloud-build-using-google-analytics.390803/#post-2549911 In the class PostBuildProcessor modify the method 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" };

Save the Unity project and by now the iOS Unity Build Cloud should work

查看更多
做自己的国王
7楼-- · 2019-01-19 00:20

I had the same problem, just fixed it.

Find the Podfile file and open it in a text editor. remove

, :integrate_targets => false

in the second line so it says: install! 'cocoapods'

Then add a new line after platform: ios...

use_frameworks!

Then open a terminal screen and go to the directory of this project. Type 'pod install' and enter. If everything goes well a workspace file is created and a message appears that you should open the workspace in Xcode in stead of the project. So close the project in xcode and open the projectname.xcworkspace file. Now Xcode will open the workspace and you will be able to run the project. You may have to adjust your Deployment Target to 8.0. Hope this works for you

查看更多
登录 后发表回答