xamarin / GoogleApisForiOSComponents

MIT License
225 stars 156 forks source link

.NET 8 iOS app build error when using Xamarin.Firebase.iOS.Core NuGet: bitcode_strip: missing argument(s) #646

Open PureWeen opened 5 months ago

PureWeen commented 5 months ago

Issue moved from dotnet/maui#19946


From @awalker-dsg on Wednesday, January 17, 2024 4:02:37 PM

Description

After updating our app (which targets Android and iOS) from net7.0 to net8.0, we started getting the following error when building for iOS:

Xamarin.Firebase.iOS.Core.targets(216,5): error : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip: missing argument(s) to: -o option
:
Xamarin.Firebase.iOS.Core.targets(216,5): error MSB3073: The command ""$(xcrun -find bitcode_strip)"  -r -o " exited with code 1.

(The full text of the error message can be found at the end of this ticket)

This error was reported as a Xamarin GoogleApisForiOSComponents issue on 29 Oct 2023. However, it was closed in Jan 2024 by the issue's author with the explanation that this sample repo helped solve the issue. However, we tried changes suggested there and it did not fix the issue for us.

Steps to Reproduce

The MAUI test project found at the sample repo link below was created using the VS wizard. It was modified so it only targets iOS, and a reference to Xamarin.Firebase.iOS.Core v8.10.0.3 was added.

Using that sample code, here are the steps to reproduce the issue.

  1. Get the repro project from the link below.
  2. Open the .sln in Visual Studio on a PC
  3. Pair to a Mac so the app can be built for iOS. (The steps to do that are WAY beyond the scope of this write-up.)
  4. Set the build target to Release
  5. Right click on the project and select Properties > iOS > "Bundle Signing" and set the provisioning profile. (Again, that's beyond the scope of this write-up.)
  6. Click on Build > Rebuild Solution
  7. If the problem exists, the build will fail with the error in the description. If fixed, the app builds successfully.

Link to public reproduction project repository

https://github.com/awalker_dsg/MauiApp_StripBitcodeIssue

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

This is a iOS app build error, so it's not related to a specific version of iOS.

Did you find any workaround?

Ultimately the error seems to be caused by changes made to address MAUI issue 12863. The error can be traced to this block of code in the Xamarin.Firebase.iOS.Core v8.10.0.3 NuGet's \buildTransitive\Xamarin.Firebase.iOS.Core.targets file:

<Target Name="_FirebaseStripBitcodeFromFrameworksOnWindows"
        Condition="'$(IsMacEnabled)'=='true'">
    <!-- Get the frameworks to strip bitcode -->
    <FindInList 
    CaseSensitive="false"
    List="@(_FrameworkNativeReference)"
    ItemSpecToFind="%(_FrameworkNamesToStripBitcode.Identity)"
    MatchFileNameOnly="True">
    <Output TaskParameter="ItemFound" ItemName="_FrameworksToStripBitcode"/>
    </FindInList>

    <!-- Strip the bitcode from frameworks -->
    <Exec SessionId="$(BuildSessionId)"
        Command="&quot;%24(xcrun -find bitcode_strip)&quot; %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity)" />

    <CopyFileFromBuildServer 
    SessionId="$(BuildSessionId)" 
    File="%(_FrameworksToStripBitcode.Identity)" 
    TargetFile="%(_FrameworksToStripBitcode.Identity)" /> 
</Target>

We were able to work-around the issue by modifying the Target statement as shown below to skip this target when the target framework is net8:

<Target Name="_FirebaseStripBitcodeFromFrameworksOnWindows"
      Condition="'$(IsMacEnabled)'=='true' AND !$(TargetFramework.Contains('net8'))">

After this change is made, the app builds successfully.

Of course, making local changes to NuGets is less than ideal, so this change (or something similar) needs to be made in the public Xamarin.Firebase.iOS.Core NuGet.

Relevant log output

C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.0.8490\targets\Xamarin.Shared.Sdk.targets(743,3): warning MT7091: The framework C:/Users/xxxx/.nuget/packages/xamarin.firebase.ios.core/8.10.0.3/lib/net6.0-ios15.4/Firebase.Core.resources/GoogleUtilitiesComponents.xcframework/ios-arm64/GoogleUtilitiesComponents.framework is a framework of static libraries, and will not be copied to the app.
"$(xcrun -find bitcode_strip)"  -r -o
C:\Users\xxxx\.nuget\packages\xamarin.firebase.ios.core\8.10.0.3\buildTransitive\Xamarin.Firebase.iOS.Core.targets(216,5): error : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip: missing argument(s) to: -o option
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip input [-r | -m | -l] [-keep_cs] -o output
C:\Users\xxxx\.nuget\packages\xamarin.firebase.ios.core\8.10.0.3\buildTransitive\Xamarin.Firebase.iOS.Core.targets(216,5): error MSB3073: The command ""$(xcrun -find bitcode_strip)"  -r -o " exited with code 1.
PureWeen commented 5 months ago

Issue moved from dotnet/maui#19946


From @drasticactions on Sunday, January 21, 2024 12:30:37 PM

@rolfbjarne What do you think about this? I'm not sure there's any MAUI UI tooling that would influence this.

PureWeen commented 5 months ago

Issue moved from dotnet/maui#19946


From @rolfbjarne on Monday, January 22, 2024 4:35:49 PM

This seems to be an issue for https://github.com/xamarin/GoogleApisForiOSComponents.

You might be able to work around it by redefining the _FirebaseStripBitcodeFromFrameworksOnWindows target in your csproj to do nothing:

<Target Name="_FirebaseStripBitcodeFromFrameworksOnWindows" />
mofdaddy commented 3 months ago

@rolfbjarne Hi, who are we supposed to approach to request the Xamarin.Firebase.iOS.* nugets gets updated to newest versions, for instance Analytics and dependencies to 10.x ?

I have tried different places, also asked @Redth for some info elsewhere. Not getting response anywhere from.

I have myself tried to get Analytics, Core and Installations updated based on the repo by AdamEssenmacher.

But I am getting errors when building for physical device: Undefined symbols for architecture arm64. I'm green regarding bindings and can't seem to nail it.

rolfbjarne commented 2 months ago

@rolfbjarne Hi, who are we supposed to approach to request the Xamarin.Firebase.iOS.* nugets gets updated to newest versions, for instance Analytics and dependencies to 10.x ?

I have tried different places, also asked @Redth for some info elsewhere. Not getting response anywhere from.

This is where the action is happening: https://github.com/dotnet/maui/discussions/20359

mofdaddy commented 2 months ago

Yes sorry - I found out after I asked you @rolfbjarne 👍