VS2022下Xamarin开发iOS应用集成Firebase真机运行报错求助
I’m building a company app using C# and Xamarin with Visual Studio 2022. Testing goes smoothly on Android physical devices, Android emulators, and iOS simulators—but the app fails to launch on a real iPhone. Here’s what’s happening:
First Error: UnpackFrameworks Task Failure
When I try to deploy to the iPhone, I get this build error immediately:
The "UnpackFrameworks" task failed unexpectedly. System.IO.IOException: The file 'obj\iPhone\Debug\Frameworks\FirebaseFirestore.framework\FirebaseFirestore' already exists. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost) at System.IO.FileInfo.CopyTo(String destFileName) at Xamarin.iOS.Tasks.Windows.Zip.CopyDirectory(String source, String destination) in /Users/builder/azdo/_work/2/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Zip.cs:line 31 at Xamarin.iOS.Tasks.Windows.Zip.Extract(String sourceFileName, String destinationPath) in /Users/builder/azdo/_work/2/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Zip.cs:line 17 at Xamarin.iOS.HotRestart.Tasks.UnpackFrameworks.Execute() in /Users/builder/azdo/_work/2/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Tasks/UnpackHotRestartFrameworks.cs:line 55 at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
I’ve already tried deleting the obj and bin folders multiple times, but the error keeps coming back.
Second Error: Firebase TypeInitializationException
After modifying the Xamarin.iOS.HotRestart.targets file to work around the first issue, the app now throws a runtime error related to Firebase:
Xamarin.PreBuilt.iOS[635:177579] System.TypeInitializationException: The type initializer for 'Plugin.CloudFirestore.FirestoreProvider' threw an exception. ---> System.ArgumentNullException: Value cannot be null. Parameter name: firestore at Plugin.CloudFirestore.FirestoreWrapper..ctor (Firebase.CloudFirestore.Firestore firestore) <0x104558138 + 0x0001a> in <xxxxxxxxxxxxxxxxxxxxx>:0 at Plugin.CloudFirestore.FirestoreProvider..cctor () <0x1039aa4c0 + 0x00014> in <xxxxxxxxxxxxxxxxxxxxx>:0 --- End of inner exception stack trace --- at Plugin.CloudFirestore.CloudFirestoreImplementation.get_Instance () <0x1039a99b0 + 0x00000> in <xxxxxxxxxxxxxxxxxxxxx>:0
The weird thing is: if I remove all Firebase components from the app, it runs perfectly fine on the physical iPhone.
Does anyone have a solution to get Firebase working correctly on real iOS devices with Xamarin?
内容的提问来源于stack exchange,提问作者Spack09

