stasel / WebRTC

Unofficial distribution of up to date WebRTC framework binaries for iOS and macOS
Other
359 stars 76 forks source link

Mac Catalyst issue #44

Closed CedricEugeni closed 1 year ago

CedricEugeni commented 1 year ago

Hi @stasel

I added your framework as a dependency of my app using Xcode & SPM. I'm using the latest 103 version and it works fine on iOS.

But when I tried to add support for Mac Catalyst for my app & run on my Mac using Mac Catalyst build, I get the following error : SCR-20220727-lz9

Do you have any idea about why I get this error ? 🤔

I tried to download the .xcframework to add it manually instead of using SPM to be able to switch to embed & sign as mentioned in another issue on this repo, but it gave me the same error. I also tried to get the .framework file for Mac Catalyst inside the .xcframework to add it manually, but no success here either.

If it doesn't work, do you know if there is any way to tell Xcode that I'd like to use the macOS framework when building against Catalyst ? 🤔

alex-reilly-pronto commented 1 year ago

I'm getting the same error on iOS when I run tests, but not when I run the app. I have the same project setup described here where I have a main app target ("Pronto") containing my views which imports a local Swift package ("ProntoCore") containing all of the business logic and unit tests in the same project. All my tests are contained in the local package.

Assertions: System: Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at /Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Logs/Test/Test-Pronto-2022.07.27_14-09-07--0700.xcresult. (Underlying Error: The bundle “ProntoCoreTests” couldn’t be loaded. The bundle couldn’t be loaded. Try reinstalling the bundle. dlopen(/Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/ProntoCoreTests.xctest/ProntoCoreTests, 0x0109): Library not loaded: @rpath/WebRTC.framework/WebRTC
  Referenced from: /Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/ProntoCoreTests.xctest/ProntoCoreTests
  Reason: tried: '/Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC' (code signature in <4C4C44AE-5555-3144-A119-79EE6A729100> '/Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC' not valid for use in process: Trying to load an unsigned library),
// a bunch of lines of Xcode searching different paths for the library and not finding it

I've confirmed with code-sign that the binary is indeed unsigned.

$ codesign -dv /Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC
/Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC: code object is not signed at all

If I manually sign it and then rerun tests, the code signing is wiped out

$ xcrun codesign -s - /Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC
$ codesign -dv /Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC
Executable=/Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC
Identifier=org.webrtc.WebRTC
Format=bundle with Mach-O universal (x86_64 arm64)
CodeDirectory v=20400 size=60778 flags=0x2(adhoc) hashes=1893+3 location=embedded
Signature=adhoc
Info.plist entries=22
TeamIdentifier=not set
Sealed Resources version=2 rules=10 files=89
Internal requirements count=0 size=12

// Run tests in Xcode
$ codesign -dv /Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC
/Users/alex/Library/Developer/Xcode/DerivedData/Pronto-cuatvjxrybrkkjcdkkiswkubduqa/Build/Products/Debug-iphonesimulator/WebRTC.framework/WebRTC: code object is not signed at all

Tests run fine from the command line with swift test --package-path ProntoCore, but of course you lose the ability to debug effectively so this isn't a long term fix. I've also tried adding this library as a dependency to the main target and test target, but that hasn't helped.

I'm using release 103 of the library and the most recent stable Xcode release (13.4.1). I won't be able to share an example project.

alex-reilly-pronto commented 1 year ago

I was actually able to work around this by adding a script to my build phase running the code signing command

xcrun codesign -s - /path/to/webrtc/binary/in/the/error/message
CedricEugeni commented 1 year ago

@alex-reilly-pronto what you are saying is that if you add a run script build phase with this command, to manually sign the WebRTC framework, then you are able to run your app ? 🤔 I'll try that later and see if it works on my side, trying to run it using Mac catalyst 😊

alex-reilly-pronto commented 1 year ago

@CedricEugeni Yep! No idea if it will work for you or if it has any consequences, but it got my tests running.

stasel commented 1 year ago

Another workaround I have found is to disable library validation. This can be useful when debugging:

image

tmolitor-stud-tu commented 1 year ago

I think the reason is this: https://blog.inventic.eu/2015/03/os-x-codesign-failed-bundle-format-is-ambiguous-could-be-app-or-framework/

WebRTC-lib/WebRTC.xcframework$ ls -lR . | grep ^l lrwxrwxrwx 1 thilo thilo 24 24. Okt 03:32 Headers -> Versions/Current/Headers lrwxrwxrwx 1 thilo thilo 24 24. Okt 03:32 Modules -> Versions/Current/Modules lrwxrwxrwx 1 thilo thilo 26 24. Okt 03:32 Resources -> Versions/Current/Resources lrwxrwxrwx 1 thilo thilo 1 24. Okt 03:32 Current -> A lrwxrwxrwx 1 thilo thilo 24 24. Okt 03:32 Headers -> Versions/Current/Headers lrwxrwxrwx 1 thilo thilo 24 24. Okt 03:32 Modules -> Versions/Current/Modules lrwxrwxrwx 1 thilo thilo 26 24. Okt 03:32 Resources -> Versions/Current/Resources lrwxrwxrwx 1 thilo thilo 23 24. Okt 03:32 WebRTC -> Versions/Current/WebRTC lrwxrwxrwx 1 thilo thilo 1 24. Okt 03:32 Current -> A

@stasel Question is: how to solve this?

tmolitor-stud-tu commented 1 year ago

@alex-reilly-pronto to what target exactly did you add this build-phase script?

alex-reilly-pronto commented 1 year ago

@tmolitor-stud-tu My main app target, and my test target.

tmolitor-stud-tu commented 1 year ago

@stasel Ok, I found the underlying error: https://github.com/stasel/WebRTC/blob/latest/scripts/build.sh#L183

XCode wants two things, your released xcframework zip does not have:

  1. WebRTC.xcframework/ios-x86_64_arm64-maccatalyst/WebRTC.framework/WebRTC must be a symlink to WebRTC.xcframework/ios-x86_64_arm64-maccatalyst/WebRTC.framework/Versions/Current/WebRTC
  2. WebRTC.xcframework/ios-x86_64_arm64-maccatalyst/WebRTC.framework/Versions/Current/WebRTC must be the binary at WebRTC.xcframework/ios-x86_64_arm64-maccatalyst/WebRTC.framework/WebRTC in your zip file, not the one at WebRTC.xcframework/ios-x86_64_arm64-maccatalyst/WebRTC.framework/Versions/Current/WebRTC (that one is not multiarch, the one that should be a symlink is)

I did the following inside the Pods/WebRTC-lib/WebRTC.xcframework/ios-x86_64_arm64-maccatalyst/WebRTC.framework/ dir where the catalyst parts of your released zip get extracted:

rm "Versions/Current/WebRTC"
mv "WebRTC" "Versions/Current/WebRTC"
ln -s "Versions/Current/WebRTC"

After doing this everything compiles and codesigns and the app works like it should :)

tmolitor-stud-tu commented 1 year ago

I've created a PR which fixes your build script: #52

tmolitor-stud-tu commented 1 year ago

I've created a branch containing a fixed podspec and source. You can add it for the M106 build like so until stasel has published fixed builds: pod 'WebRTC-lib', git: 'https://github.com/monal-im/WebRTC', branch: 'tempfix'

CedricEugeni commented 1 year ago

hi @tmolitor-stud-tu,

Thanks for the updates you provided! If I'm using SwiftPM to handle dependencies, will it work with your branch or not ?

tmolitor-stud-tu commented 1 year ago

Hi @CedricEugeni I just updated my tempfix branch to make it work with SwiftPM and Carthage. So: yes, now it does :)

CedricEugeni commented 1 year ago

@tmolitor-stud-tu with your branch, did you achieve connecting using a webRTC connection, then displaying a video feed in the app using a WebRTCClient.setupRemoteRenderer method with a RTCMTLVideoView view ? 🤔 Because using your branch on my side, I can compile and run my app smoothly, but my WebRTC connection does not seem to work since video does not display inside the view. If you want I can dig deeper to see if it's the connection that's not working or the video rendering, just let me know to see if we can move on together on this subject 😊

I can also confirm that using your branch, it works on iOS and macOS (design for iPad) target.

tmolitor-stud-tu commented 1 year ago

@CedricEugeni I did not implement video calls in Monal (the app I'm using the WebRTC lib for) yet, only audio calls. Unfortunately audio calls seem to have a bug on macOS that prevents the device to ring (that's not connected to WebRTC, but prevents me to test audio calls on macOS currently). On iOS everything works (but still only audio calls).

If you want I can dig deeper to see if it's the connection that's not working or the video rendering, just let me > know to see if we can move on together on this subject blush

It would be great if you could dig deeper :)

CedricEugeni commented 1 year ago

@tmolitor-stud-tu I get into callbacks that tells me that WebRTC connection is ok. Seems like my issue is coming from the video renderer. Not sure how I could proceed to know which part doesn't work as intended and maybe how to make it work

tmolitor-stud-tu commented 1 year ago

@CedricEugeni hmmm...well...does video support work on iOS? I will add video support to Monal in a few months. If that problem still persists then, I'll keep you updated if I find a solution.

alex-reilly-pronto commented 1 year ago

@CedricEugeni Did you have the video renderer working previously? I can confirm that video rendering is working in my application on iOS.

CedricEugeni commented 1 year ago

@alex-reilly-pronto When I'm using @tmolitor-stud-tu fork & branch, video renderer works well on iOS and on macOS (designed for iPad) modes. But video renderer does not work on macOS catalyst mode

CedricEugeni commented 1 year ago

When I'm using this repo latest build, it works well on iOS & macOS (design for iPad) too

stasel commented 1 year ago

Thanks everyone for finding the issue and helping to solve it. I applied the fix and released a new version M107 🎉

I'm super happy to see a nice friendly conversation that support each other ❤️

tmolitor-stud-tu commented 1 year ago

I'm deleting my forked repo now, please use upstream again :)

CyonAlexRDX commented 1 year ago

See #61 if anyone with an M1 gets Library not loaded: @rpath/WebRTC.framework/WebRTC when running on iOS simulator