Search code examples
androidfirebaseunity-game-enginegoogle-analyticsgoogle-analytics-firebase

Building Unity project with Firebase Google Analytics SDK fails: "Could not load file or assembly 'UnityEditor.iOS.Extensions.Xcode"


The Problem

I am trying to integrate Firebase Google Analytics into my existing Unity project (a mobile game for iOS and Android). I was following the instructions on https://firebase.google.com/docs/unity/setup (all the prerequisites are fullfilled). Unfortunately when trying to build the Android version on Windows I get the following errors:

BadImageFormatException: Could not resolve field token 0x040000dc, due to: Could not load type of field 'Firebase.Editor.XcodeProjectModifier:projectInfoDoc' (2) due to: Could not load file or assembly 'UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:(null) signature:<none> assembly:C:\Users\mform\Code\guessme\Assets\Firebase\Editor\Firebase.Editor.dll type:XcodeProjectModifier member:(null) signature:<none>
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <567df3e0919241ba98db88bec4c6696f>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <567df3e0919241ba98db88bec4c6696f>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <567df3e0919241ba98db88bec4c6696f>:0)
UnityEditor.Build.BuildPipelineInterfaces+AttributeCallbackWrapper.OnPostprocessBuild (UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:158)
UnityEditor.Build.BuildPipelineInterfaces+<OnBuildPostProcess>c__AnonStorey2.<>m__1 (UnityEditor.Build.IPostprocessBuildWithReport bpp) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:398)
UnityEditor.Build.BuildPipelineInterfaces.InvokeCallbackInterfacesPair[T1,T2] (System.Collections.Generic.List`1[T] oneInterfaces, System.Action`1[T] invocationOne, System.Collections.Generic.List`1[T] twoInterfaces, System.Action`1[T] invocationTwo, System.Boolean exitOnFailure) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:356)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)

Error building Player: BadImageFormatException: Could not resolve field token 0x040000dc, due to: Could not load type of field 'Firebase.Editor.XcodeProjectModifier:projectInfoDoc' (2) due to: Could not load file or assembly 'UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:(null) signature:<none> assembly:C:\Users\mform\Code\guessme\Assets\Firebase\Editor\Firebase.Editor.dll type:XcodeProjectModifier member:(null) signature:<none>

I don't understand why it attempts to load this assembly, which is cleary only intended for iOS anyway. And I don't know how to prevent it or get rid of this bug.

The Setup

  • Windows 10 Pro
  • existing Unity project with working Android/iOS builds
  • Unity 2019.2.16f1
  • Using the OpenJDK and Android SDK/NDK packaged with Unity
    • OpenJDK 1.8
    • Android SDK tools 29.0.2
  • current dependencies (all working as expected)
  • I added Google Analytics as described in https://firebase.google.com/docs/unity/setup
    • I completed all the steps
    • When executed in the editor the CheckAndFixDependenciesAsync continuation is called and the Firebase Dependency status is "Available"

Build Settings

enter image description here

Player Settings

enter image description here

Solution Attempts

  • I reset all changes via Git and started the steps again from the start, importing the SDK unity package anew
  • Using the Play Service resolver
    • I updated the Version Handler
    • I forced resolving of the Android dependencies (which works)
  • deleted the Library folder and rebuild

None of these helped unfortunately. I'd be very grateful for any pointers into the right direction.


Solution

  • Thanks to a hint by @Cœur (thanks a 1000 times) I installed the iOS module in the Unity editor (even though I was only trying to build the Android version on Windows). With the iOS module installed the Android build worked.