square / in-app-payments-ios

Public repository that hosts the Square In-App Payments SDK iOS binaries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simulator not working on Apple Silicon Macs

joshluongo opened this issue · comments

If you attempt to run an app that links against this on an M1 Mac, the build fails with this error

ignoring file /Users/josh/Library/Developer/Xcode/DerivedData/sq-test-guhepivbteygalcaxobzzvqyzrvq/Build/Products/Debug-iphonesimulator/SquareInAppPaymentsSDK.framework/SquareInAppPaymentsSDK, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64

Installed by Swift Package Manager

I was able to workaround this by manually patching the framework using vtool and lipo. This is not good solution but got me out of trouble.

Happy to share the workaround if required.

Hi @joshluongo same issue here :-(. Definitely not a good solution...do you mind sharing more details about your workaround?

Hi @joshluongo same issue here :-(. Definitely not a good solution...do you mind sharing more details about your workaround?

Here is my workaround, just a note by design I'm only including arm64-simulator so you still use the offical version to build on device. I have a pre-patched binary in this fork I made https://github.com/joshluongo/in-app-payments-ios/tree/master/XCFrameworks

If you want to patch it yourself heres how I did it.

# Setup a temp folder and clone the repo.
mkdir /tmp/square-sdk-patch
cd /tmp/square-sdk-patch
git clone https://github.com/square/in-app-payments-ios.git

# Make a copy of the framework for patching
cp -r in-app-payments-ios/XCFrameworks/SquareInAppPaymentsSDK.xcframework SquareInAppPaymentsSDK-Patch.xcframework

# Move the ios-arm64 to ios-arm64-simulator
mv SquareInAppPaymentsSDK-Patch.xcframework/ios-arm64 SquareInAppPaymentsSDK-Patch.xcframework/ios-arm64-simulator

# Delete the x86_64 version
rm -r SquareInAppPaymentsSDK-Patch.xcframework/ios-x86_64-simulator

# Use vtool to patch recreate the binary.
# Meaning on the numbers in build verison.
# 7 = Simulator -- This is the platform number
# 12.0 - Min OS
# 14.5 - SDK Version
vtool -arch arm64 -set-build-version 7 12.0 14.5 SquareInAppPaymentsSDK-Patch.xcframework/ios-arm64-simulator/SquareInAppPaymentsSDK.framework/SquareInAppPaymentsSDK -output SquareInAppPaymentsSDK-Patch.xcframework/ios-arm64-simulator/SquareInAppPaymentsSDK.framework/SquareInAppPaymentsSDK

# Create Info.plist so it only has the arm64 simulator.
cat <<EOF > SquareInAppPaymentsSDK-Patch.xcframework/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>AvailableLibraries</key>
    <array>
        <dict>
            <key>LibraryIdentifier</key>
            <string>ios-arm64-simulator</string>
            <key>LibraryPath</key>
            <string>SquareInAppPaymentsSDK.framework</string>
            <key>SupportedArchitectures</key>
            <array>
                <string>arm64</string>
            </array>
            <key>SupportedPlatform</key>
            <string>ios</string>
            <key>SupportedPlatformVariant</key>
            <string>simulator</string>
        </dict>
    </array>
    <key>CFBundlePackageType</key>
    <string>XFWK</string>
    <key>XCFrameworkFormatVersion</key>
    <string>1.0</string>
</dict>
</plist>
EOF

# Codesign for the simulator ( Required for Apple Silicon :( )
xcrun codesign --sign - SquareInAppPaymentsSDK-Patch.xcframework

Wow thanks so much @joshluongo for sharing this. Much appreciated!

Wow thanks so much @joshluongo for sharing this. Much appreciated!

No worries! I have raised this issue with my partner manager too so hopefully there is an official solution soon.

Thanks much! Yeah, as I recall Firebase had this same problem last year..they did (eventually...) fix it, so hopefully Square will as well.

Just an update: This is still not fixed as of 1.5.6

This is still broken in 1.5.8. @mseijas

Are there any plans whatsoever to address this? Quite annoying to need workarounds for this.

Posting to see if there are any updates on this, must be affecting quite a lot of developers. Workaround described above works for me, but does mean I can't import via CocoaPods. A bit of a pain to have to do. Any update on this would be greatly appreciated.

Affecting us as well. Wish there were a solution. Using rosetta in the meantime and build times are killing us.

Amazed that this is still an issue. It's a real pain to have to do the hack above for simulator builds and then switch back to the cocoapods version for device builds... It's not like the M1 chips have just been announced. Would be great to get this sorted.

The rosetta solution is going to stop working as of Xcode 14.3, https://developer.apple.com/documentation/xcode-release-notes/xcode-14_3-release-notes#Deprecations . @havenwood Any updates on patching this without having to use my workaround?

This appears to be fixed as of v1.6.1 🥳

If you still have issues and you're using SPM make sure you added the script to your build phases https://github.com/square/in-app-payments-ios/blob/master/SPM_README.md, that solved the build issues I had.