Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 12 GM Archive Error SPM - unexpected Mach-O header code: 0x72613c21 #6472

Closed
Neilfau opened this issue Sep 16, 2020 · 160 comments
Closed

Comments

@Neilfau
Copy link

Neilfau commented Sep 16, 2020

[REQUIRED] Step 1: Describe your environment

  • Xcode version: Xcode 12 GM (12A7208)
  • Firebase SDK version: 6.32-spm-beta
  • Firebase Component: Analytics
  • Component version: 6.32
  • Installation method: Swift Package Manager

[REQUIRED] Step 2: Describe the problem

When trying to upload an archive to App Store connect Xcode 12 GM gives me the following error:

Found an unexpected Mach-O header code: 0x72613c21

If I change my build configuration to development the app builds and runs fine but if I switch to a release configuration and try to run the app on the latest iOS 14 iPhone 11 Pro simulator I get the following error:

Undefined symbol: _OBJC_CLASS_$_FIRAnalytics

and the following warnings:

missing required architecture arm64 in file /Users/neil/Library/Developer/Xcode/DerivedData/Kantinebaas-gnwjztsimxavkscwhhoheneylhus/Build/Products/Alpha-iphonesimulator/FirebaseAnalytics.framework/FirebaseAnalytics

missing required architecture arm64 in file /Users/neil/Library/Developer/Xcode/DerivedData/Kantinebaas-gnwjztsimxavkscwhhoheneylhus/Build/Products/Alpha-iphonesimulator/FIRAnalyticsConnector.framework/FIRAnalyticsConnector

missing required architecture arm64 in file /Users/neil/Library/Developer/Xcode/DerivedData/Kantinebaas-gnwjztsimxavkscwhhoheneylhus/Build/Products/Alpha-iphonesimulator/GoogleAppMeasurement.framework/GoogleAppMeasurement (2 slices)

Steps to reproduce:

Archive and try to submit project with a release build configuration using Xcode 12 GM with Firebase analytics added to the project using SPM.

@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@ryanwilson
Copy link
Member

Thanks for the report - I'll look into this right away. To confirm, did you add the -ObjC linker option for Analytics?

@Neilfau
Copy link
Author

Neilfau commented Sep 16, 2020

@ryanwilson yeah it was the first thing I checked! I went back to the Xcode 12 beta 6 and had no issues at all. Something that might be of note is apple released a new version of the Xcode 12 GM with build number of (12A7209). Im currently downloading it and I will try with that version also as it could of been a Xcode bug.

@ryanwilson
Copy link
Member

ryanwilson commented Sep 16, 2020

Yeah I'm downloading it as well, will report back when I can repro or not. Currently trying on 12A7208 but it's currently hanging when trying to check out grpc.. 😬 EDIT: it resolved, just took a while.

@ryanwilson
Copy link
Member

I reproduced the issue, still unzipping the new GM seed and will test it there but I'll see if I can find a workaround for the first GM seed.

@ryanwilson
Copy link
Member

Initial thought: if it's packaging for release, it may be trying to include all the architectures to run on device and it's not expecting to be run on the simulator? That's why it's searching for the arm64 architecture even though it's running on an x86 simulator. I tried running on device and get a different issue though, will try the new Xcode version.

@Neilfau
Copy link
Author

Neilfau commented Sep 16, 2020

Yeah I think its something to do with that also.

@Neilfau
Copy link
Author

Neilfau commented Sep 16, 2020

I can confirm I get the same issue with the new seed also.

@ryanwilson
Copy link
Member

Same re: running with Release. I am able to Archive though, selecting "Any iOS Device (arm64)" and hitting "Product -> Archive" in the menu.

Based on the original issue - you're unable to archive right?

@Neilfau
Copy link
Author

Neilfau commented Sep 16, 2020

I can archive its when I try to upload to the App Store I get the Found an unexpected Mach-O header code: 0x72613c21 error. The other error was when I tried to run it on a simulator.

@ThePragmaticArt
Copy link

ThePragmaticArt commented Sep 16, 2020

Yeah, so right now the firebase framework artifacts are being copied into the /Frameworks folder of the ipa and are embedded. The frameworks themselves are static frameworks.... If you delete them from the xcarchive manually, everything works as expected. I'm not sure what's running behind the scenes to trigger this embedding phase though, but it needs to be removed.

@ThePragmaticArt
Copy link

I can archive its when I try to upload to the App Store I get the Found an unexpected Mach-O header code: 0x72613c21 error. The other error was when I tried to run it on a simulator.

This is due to a static framework being embedded within the /Frameworks folder of the archive.

@ryanwilson
Copy link
Member

Thanks @ThePragmaticArt for finding that! I'm wondering if that's an Xcode bug or that's an artifact based on how we set up our Package.swift manifest. I'll see about reproducing with the upload case and filing some Feedback about it - especially since binary packages are new in SwiftPM.

@ThePragmaticArt
Copy link

Thanks @ThePragmaticArt for finding that! I'm wondering if that's an Xcode bug or that's an artifact based on how we set up our Package.swift manifest. I'll see about reproducing with the upload case and filing some Feedback about it - especially since binary packages are new in SwiftPM.

Mach-O universal binary with 2 architectures: [i386:current ar archive random library] [x86_64:current ar archive random library]
FirebaseAnalytics (for architecture i386):	current ar archive random library
FirebaseAnalytics (for architecture x86_64):	current ar archive random library

It seems to have to do with the xcframework bundles included. That's at least the only lead I can see. Actual root cause, I'm not entirely sure. It does seem to be those 3 artifacts though.

@ryanwilson
Copy link
Member

Those are in fact the only binary frameworks that we offer - all the rest are source based. It could be due to packaging of the XCFrameworks since they're manually generated from regular .frameworks (we hope to be changing over to build XCFrameworks directly very soon), or it could be an issue with binary frameworks in general on the Xcode side.

@ThePragmaticArt
Copy link

ThePragmaticArt commented Sep 16, 2020

@ryanwilson I believe Realm has some embedded xcframework artifacts as well but do not have this issue:

https://github.com/realm/realm-cocoa.git

https://github.com/realm/realm-cocoa/tree/master/core

Not sure if that helps as a reference point for something that might be similar.

@ryanwilson
Copy link
Member

@ThePragmaticArt that must be outside of Swift Package Manager though - see here for where we define binaryTargets:

.binaryTarget(
name: "FirebaseAnalytics",
url: "https://dl.google.com/firebase/ios/swiftpm/6.32.1/FirebaseAnalytics.zip",
checksum: "125c37be61cf83162de34bfc73e5526f995bf9d40e9dcac896f024c333aa9b93"
),
.binaryTarget(
name: "FIRAnalyticsConnector",
url: "https://dl.google.com/firebase/ios/swiftpm/6.32.1/FIRAnalyticsConnector.zip",
checksum: "d09f1655c5e4a382176ee1a447c2fa016123e9d7b2427a3223c8cb62ce89bc7d"
),
.binaryTarget(
name: "GoogleAppMeasurement",
url: "https://dl.google.com/firebase/ios/swiftpm/6.32.1/GoogleAppMeasurement.zip",
checksum: "0a20a3766109690c692f6488adb733d3f41901bf74f57fd2f63cb260a265a938"
),

This was introduced in swift-tools-version:5.3 and Realm is still on 5.0 and doesn't have any binaryTargets in their Package.swift file. We ship xcframeworks for our zip file and haven't had this issue, so I assume it's specific to SwiftPM's integration of binaries.

@ThePragmaticArt
Copy link

@ryanwilson interesting. I don't have anything separate I can test. I might be able to spin up something later today just to play around and see. Not sure if there are any quick samples that are already out there that could validate the behavior. It would be disappointing to hear there's a bug in the GM that requires a script to clean this up.

@ryanwilson
Copy link
Member

ryanwilson commented Sep 16, 2020

It looks like this is related to PSPDFKit-labs/radar.apple.com@9b6c842 (FB7785691). This was an issue opened stating that the archive should include those frameworks, fixed in the GM, and now we're running into an issue for Firebase.

@steipete - are you able to share how the XCFrameworks are generated and anything that may be going on here? Perhaps static vs dynamic frameworks? (Also, thanks for having that repo and the context - we would have been blind to it otherwise).

@steipete
Copy link
Contributor

Here's an yet unreleased blog post how we explain our SwiftPM integration:
https://pspdfkit.com/blog/2020/binary-frameworks-as-swift-packages/ - will become a public URL in a few days but I'm ok with sharing it early here if it helps.

We use dynamic frameworks only, not statics, and the above radar has been fixed in the GM. Let me know if that helps, happy to share more to get Firebase across to SwiftPM! I also know the SwiftPM maintainer if we need further help.

@ryanwilson
Copy link
Member

ryanwilson commented Sep 16, 2020

Thanks @steipete, helpful as always! :D That must be the issue, we package FrameworkAnalytics as a static framework. Will have to do some digging and chat offline with @paulb777 about how to proceed, but at least we have a workaround right now.

Workaround:

Yeah, so right now the firebase framework artifacts are being copied into the /Frameworks folder of the ipa and are embedded. The frameworks themselves are static frameworks.... If you delete them from the xcarchive manually, everything works as expected.

@sjmueller
Copy link

Keep in mind that there is another issue cropping up on Xcode 12 GM when deploying to device Code: -402620388 No code signature found:

https://forums.swift.org/t/swiftpm-binarytarget-dependency-and-code-signing/38953

@din
Copy link

din commented Sep 17, 2020

As a temporary workaround for building add Post Action to your Scheme with the following content:

rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/Frameworks/"*.framework
rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/Plugins/"*.framework

@kylebrowning
Copy link

@din that workaround did not work for me :(

@paulb777
Copy link
Member

It looks like a workaround is excluding arm64 in the Build Settings. See https://stackoverflow.com/a/63622570

@kylebrowning
Copy link

@paulb777 that doesn't work either, can't build to device.

@DaniellSousa
Copy link

Hi guys.. i solved this problem changing the code signing identity. The target and project was different and i changed all for iOS Distribution according the provision profile file.

@ROBYER1
Copy link

ROBYER1 commented Apr 6, 2021

Honestly shocked Apple haven't hotfixed this in 12.4 Xcode at least as it looks like it's been an issue for a while... ugh

@ryanwilson
Copy link
Member

Confirmed this is still fixed in the Xcode 12.5 RC released today - will leave it open until the fix is the publicly released version.

@4brunu
Copy link
Contributor

4brunu commented Apr 27, 2021

Confirmed this is still fixed in the Xcode 12.5 RC released today - will leave it open until the fix is the publicly released version.

Now that Xcode 12.5 stable is release, this issue should be fixed, right?

@ryanwilson
Copy link
Member

Confirmed that this issue is fixed in the public version of Xcode 12.5. 🎉

Thank you everyone for your patience and helping out with workarounds! If you did add a workaround for your project, it's probably best to remove it to ensure it doesn't cause any issues in the future.

Swift Package Manager Support automation moved this from To do to Done Apr 27, 2021
@testAVD
Copy link

testAVD commented Apr 28, 2021

@ryanwilson Got it actually that issue got fixed, Please can you give a brief. It went a over my head a bit.

Asking you because I faced same issue with static framework & IN XCODE 12.5.

@batuhansk
Copy link

This issue is still exist on Xcode 12.5 (12E262). I could not upload the binary to App Store without adding Post-actions script.

@ryanwilson
Copy link
Member

Hi @testAVD and @batuhansk, sorry for the trouble you're facing.

Can you please try to reproduce this in a new project and let me know if you see the issue? If so, can you please confirm:

  • You're using Xcode 12.5 (and if you have multiple Xcode versions installed, it's activated with xcode-select)
  • Which Firebase products are you including?
  • Are you using any non-Firebase products that are binaries as well? Can you list which ones?

Thanks. If we can get a clean repro on Xcode 12.5 I'll re-open this issue.

@batuhansk
Copy link

Hi @testAVD and @batuhansk, sorry for the trouble you're facing.

Can you please try to reproduce this in a new project and let me know if you see the issue? If so, can you please confirm:

  • You're using Xcode 12.5 (and if you have multiple Xcode versions installed, it's activated with xcode-select)
  • Which Firebase products are you including?
  • Are you using any non-Firebase products that are binaries as well? Can you list which ones?

Thanks. If we can get a clean repro on Xcode 12.5 I'll re-open this issue.

Hi @ryanwilson,

  • No, I do not have multiple Xcode versions. Only Xcode 12.5 (12E262).
  • I use FirebaseAnalytics, FirebaseMessaging and FirebaseRemoteConfig products.
  • Yes I do. I use Realm as binary as well.

Thanks.

@ryanwilson
Copy link
Member

ryanwilson commented May 3, 2021

@batuhansk Thanks for the confirmations. If you create a brand new project and only include FirebaseAnalytics, FirebaseMessaging, and FirebaseRemoteConfig do you see the same issue?

@firebase firebase locked and limited conversation to collaborators May 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests