I am trying to recompile the bitcode of my tvOS app, including the bundled WebRTC framework, for the purpose of being able to successfully submit the app to the App Store. This same process with the iOS app succeeds.
Upon pushing the tvOS app to the App Store, an email alerts me that:
ITMS-90562: Invalid Bundle - One or more dynamic libraries that are referenced by your app are not present in the dylib search path.
To diagnose the issue, I switched to an Ad Hoc distribution with bitcode rebuilding locally. I did this with both iOS and tvOS so that I could compare the resulting log files.
The earliest difference in the process is this, seen below, where it is apparently putting together a linkage graph.
iOS
Scanning IPA...
Complete LinkageGraph:
Streamie.app/PlugIns/StreamieNotificationService-iOS.appex/StreamieNotificationService-iOS arm64 ->
Streamie.app/Streamie arm64 ->
Streamie.app/Frameworks/WebRTC.framework/WebRTC arm64
Streamie.app/Frameworks/WebRTC.framework/WebRTC arm64 ->
tvOS (note the warning...)
Scanning IPA...
warning: Failed to resolve linkage dependency Streamie arm64 -> @rpath/WebRTC.framework/WebRTC: Could not find MachO for /private/var/folders/43/rmt6yww10fg1dbs9tzlfwvlh0000gn/T/XcodeDistPipeline.~~~nvA8Ku/Root/Payload/Streamie.app/Frameworks/WebRTC.framework/WebRTC
Complete LinkageGraph:
Streamie.app/Streamie arm64 ->
$ otool -L WebRTC.framework/WebRTC (system libs and such removed)
WebRTC.framework/WebRTC (architecture arm64):
@rpath/WebRTC.framework/WebRTC (compatibility version 0.0.0, current version 0.0.0)
$ file WebRTC.framework/WebRTC
/[snip]/webrtc/WebRTC.framework/WebRTC: Mach-O universal binary with 1 architecture: [arm64:Mach-O 64-bit dynamically linked shared library arm64]
/[snip]/WebRTC.framework/WebRTC (for architecture arm64): Mach-O 64-bit dynamically linked shared library arm64
When the bitcode building process finally fails, the log file concludes with:
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:372:in `run'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2886:in `block in CompileOrStripBitcodeInBundle'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2825:in `each'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2825:in `CompileOrStripBitcodeInBundle'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:3112:in `block in ProcessIPA'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:3073:in `each'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:3073:in `ProcessIPA'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:4035:in `<main>'" UserInfo={NSLocalizedDescription=ipatool failed with an exception: #<CmdSpec::NonZeroExitException: $ /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -L --sdk /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS15.2.sdk -o /var/folders/43/rmt6yww10fg1dbs9tzlfwvlh0000gn/T/ipatool20220214-66770-pw6k3b/thinned-out/arm64/Payload/Streamie.app/Streamie --generate-dsym /var/folders/43/rmt6yww10fg1dbs9tzlfwvlh0000gn/T/ipatool20220214-66770-pw6k3b/thinned-out/arm64/Payload/Streamie.app/Streamie.dSYM --strip-swift-symbols /var/folders/43/rmt6yww10fg1dbs9tzlfwvlh0000gn/T/ipatool20220214-66770-pw6k3b/thinned-in/arm64/Payload/Streamie.app/Streamie
Status: pid 66874 exit 1
[snip thousands of lines]
Search Path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/lib/darwin, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/appletvos, /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS15.2.sdk/usr/lib, /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS15.2.sdk/System/Library/Frameworks
WebRTC not found in dylib search path
Some additional notes:
- I can build-and-run to an Apple TV without issue.
- I can archive the app and side-load it, and run it on an Apple TV just fine.
- The resulting iOS and tvOS WebRTC frameworks are each around 620MB, which is roughly the expected size with bitcode enabled.
To build WebRTC targeting tvOS, I'm using a modification of this script, seen below, combined with the build script here.
#!/bin/bash
GN_OUT_PATH=$1
${GN_OUT_PATH}/obj/pc/peerconnection.ninja | awk '{ print $47 }')
IPHONE_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.2.sdk
TV_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS15.2.sdk
IPHONE_SYSROOT_SED=$(echo "${IPHONE_SYSROOT//\//\\/}")
TV_SYSROOT_SED=$(echo "${TV_SYSROOT//\//\\/}")
ninjas=`find ${GN_OUT_PATH} -name '*.ninja'`
ninjas=$(echo "$ninjas" | tr ' ' '\n' | sort -u | tr '\n' ' ')
for ninja in $ninjas; do
sed -i -- "s/${IPHONE_SYSROOT_SED}/${TV_SYSROOT_SED}/g" $ninja
sed -i -- "s/iphoneos-version/appletvos-version/g" $ninja
sed -i -- "s/arm64-apple-ios/arm64-apple-tvos/g" $ninja
done
My best guess at this point is that somehow the bitcode support in the WebRTC framework (for tvOS) is broken, but I don't know how verify that.