com.unity.webrtc icon indicating copy to clipboard operation
com.unity.webrtc copied to clipboard

[BUG] WebRTC with Unity as a Library / Cordova + iosRTC

Open Kerugal opened this issue 4 years ago • 11 comments

Setup: Unity as a library on iOS device. The existing code is compiled by Cordova. A plugin is used in Cordova https://github.com/cordova-rtc/cordova-plugin-iosrtc On Unity side Unity-Webrtc is used. All components build correctly as stand-alone and also as UaaL if WebRTC is not included in Unity. The following error message is thrown:

2021-11-11 17:59:48.086883+0100 XXX[11121:1943090] Error loading /var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/UnityFramework.framework/UnityFramework, 0x0109): Library not loaded: @rpath/webrtc.framework/webrtc

Referenced from: /private/var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/UnityFramework.framework/UnityFramework

Reason: tried: '/private/var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/webrtc.framework/webrtc' (no such file), '/private/var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/webrtc.framework/webrtc' (no such file), '/usr/lib/swift/webrtc.framework/webrtc' (no such file), '/private/var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/webrtc.framework/webrtc' (no such file), '/System/Library/Frameworks/webrtc.framework/webrtc' (no such file)

2021-11-11 17:59:48.087928+0100 XXX[11121:1943090] Error loading /var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/UnityFramework.framework/UnityFramework, 0x0109): Library not loaded: @rpath/webrtc.framework/webrtc

Referenced from: /private/var/containers/Bundle/Application/F8920C8F-FA77-4A40-B72C-D69636DEB42F/XXX.app/Frameworks/UnityFramework.framework/UnityFramework

For the report production, a Corodva project with iosRTC + Unity as a Library with Unity WebRTC had to be set up.

Does the application have a name conflict with the iosRTC library? Should I integrate the library differently?

Environment

  • OS: macOS
  • Unity Version 2021.1.x
  • Package version 2.4.0-exp.4

Many many Thanks Patrick

Kerugal avatar Nov 11 '21 18:11 Kerugal

@Kerugal I have never tried to built UaaS with the webrtc library. I would like to know the more detailed that you determined the cause of issue is a name conflict?

karasusan avatar Nov 12 '21 01:11 karasusan

Whether it's a name conflict, I don't know for sure - that was just a guess. However, since all components run individually, this was my first suspicion. WebRTC in a UaaL project also runs without errors. Only when I include "iosRTC" in the existing iOS project or visa versa does this error occur as soon as I switch to Unity - hence the assumption that there may be a name conflict.

As soon as I get back to the office, I'll send you some screenshots of my XCode project setup.

Kerugal avatar Nov 12 '21 07:11 Kerugal

IssueWebrtc (1) IssueWebrtc (3) IssueWebrtc (2)

Kerugal avatar Nov 12 '21 08:11 Kerugal

memo: WRS-156

karasusan avatar Nov 16 '21 03:11 karasusan

In case it helps with reproduction - here are my findings so far:

  • iOS does not allow frameworks that call other frameworks, as is the case with Unity WebRTC + Uaal. See: https://developer.apple.com/library/archive/technotes/tn2435/_index.html#//apple_ref/doc/uid/DTS40017543-CH1-PROJ_CONFIG-APPS_WITH_DEPENDENCIES_BETWEEN_FRAMEWORKS

  • If the library is moved from the Unity directory to the Cordova project and called from there, the existing Cordova WebRTC.framework file is overwritten with the Unity webrtc.framework file and leads to a name conflict.

  • The next step is to run the build_plugin_ios script and change the naming there, but this is not executable due to an ARM64 error.

Regards Patrick

Kerugal avatar Nov 17 '21 20:11 Kerugal

@Kerugal Thanks for sharing helpful information. Could you tell me more about "ARM64 error"?

karasusan avatar Nov 19 '21 01:11 karasusan

At the moment we do not own an arm64 macOS. We think that this will cause errors in the script. At least that's what the script says. Next week we will build it on an arm64 Mac and hope that this will solve the problem. Cross-compiling, between x86 and arm64 has not worked so far

Kerugal avatar Nov 21 '21 14:11 Kerugal

Small update: With the rebuilt and renamed WebRTC library, it now runs workaorund moderately.

Kerugal avatar Nov 26 '21 09:11 Kerugal

@Kerugal I can't think of any good ideas for avoiding name conflict. Do you have any ideas?

karasusan avatar Nov 27 '21 00:11 karasusan

I changed the output files in build_plugin_ios.sh to webrtcUnity.framework. Then executed each build process individually. Before building the archieve in Xcode I also changed the generated cmake files. In one file there was also a comment with the hint to rename. Afterwards the framework was mounted locally from the disk with changed names.

Certainly not a model solution, but as a workaround it worked, so that the two frameworks no longer get in each other's way.

Kerugal avatar Dec 06 '21 16:12 Kerugal

@Kerugal Thank you for trying the workaround. Let us investigate if XCode offers a workaround other.

kannan-xiao4 avatar Dec 14 '21 04:12 kannan-xiao4