AdamEssenmacher / GoogleApisForiOSComponents

A community-supported fork of the abandoned Xamarin.iOS.* binding libraries from Microsoft
MIT License
40 stars 7 forks source link

.NET 8 iOS app build error using AdamE.Firebase.iOS.Core: "bitcode_strip: missing argument(s)" #19

Closed awalker-dsg closed 1 month ago

awalker-dsg commented 1 month ago

Note: This error was originally reported as xamarin/GoogleApisForiOSComponents issue 646

We are getting the following error when using Visual Studio v17.9.6 to build an app for iOS when targeting .NET 8:

C:\.nugets\adame.firebase.ios.core\10.24.0\buildTransitive\AdamE.Firebase.iOS.Core.targets(251,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:\.nugets\adame.firebase.ios.core\10.24.0\buildTransitive\AdamE.Firebase.iOS.Core.targets(251,5): error MSB3073: The command ""$(xcrun -find bitcode_strip)"  -r -o " exited with code 1.

Steps to reproduce This MAUI test project was created using the VS wizard. It was modified so it only targets iOS, and a reference to AdamE.Firebase.iOS.Core v10.24.0 was added. Using that sample code, here are the steps to reproduce the issue.

  1. Get the repro project from the link above.
  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.

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 AdamE.Firebase.iOS.Core NuGet's \buildTransitive\AdamE.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 in the .targets file in our local NuGet repository to add AND !$(TargetFramework.Contains('net8')) to the Condition 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.

AdamEssenmacher commented 1 month ago

Hmm. It's my understanding that bitcode is completely deprecated now, so maybe that target isn't needed at all? It seems your workaround is just to ignore it anyway.

awalker-dsg commented 1 month ago

It could be that bitcode is no longer needed. The suggested change was just an attempt to follow the developers' Hippocratic Oath -- do no harm, but if you do, try not to piss off too many people.

awalker-dsg commented 1 month ago

Although the workaround temporarily takes care of the issue, it's less than ideal to modify the .targets file after the package has been installed because those changes will be lost the next time we get an update of this library.

So, we would like to get an official release with this fix. What can I do to help make that happen? I could create a fork and implement the change myself, but that seems like overkill for a one-line code change in a .targets file. Also, since I've never contributed to this project before, I would need some help because I'm not sure what the process is for submitting and completing a PR.

If I am asked to implement this change, as I hinted at in my last post I would use the suggested change as-is rather than removing the bitcode target. That seems the safest approach because it doesn't appear the presence of the bitcode target is causing problems anywhere else except when building an iOS app on Windows with net8.

AdamEssenmacher commented 1 month ago

@awalker-dsg I disagree that the approach to disable the target on Windows is the safest approach. Stripping bitcode is either important, or it isn't. If it is important, then it should run regardless of the platform that is running the build.

This said, I'm pretty confident that this bitcode stripping targets are vestigial now. The Firebase iOS SDK release notes suggest that bitcode was removed in version 10, so I think we should be safe to just remove the targets.

I just published a package for Firebase.Core that removes these targets (10.24.0.1). Please give this package a try and report back!

awalker-dsg commented 1 month ago

@AdamEssenmacher, re "I disagree..." No problem -- you're the boss!

I retested with 10.24.0.1 and that has resolved the problem. Many, many, many thanks for taking care of this and for the quick turnaround!