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
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!
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.
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 frameworks = new List() {
"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.