I am currently in the process of integrating CocoaPods in one of my projects but it seems that it cannot handle dynamic .xcframeworks correctly, at least it seems it is not working for my use case. Currently I am using the FBSDKCoreKit pod to demonstrate this issue, but this problem happens with any Pod that depends on an dynamically loaded .xcframework.
I created one iOS app target and another framework target. The framework target has a dependency on some Pod dependency which is integrated via an dynamically loaded .xcframework. At the end the framework target is linked to the iOS app target.
One thing to note: The App target is now known to CocoaPods. It does only know about the framework target. The idea is to "hide" the pod dependency behind the framework target and let the framework target do the loading of the pod dependency. But here I am not sure if this is the correct way to do it.
┌─────────┐ Linked via┌─────────┐ ┌────────────────────────────────┐
│ App │───Xcode──▶│Framework│─────▶│ Pod with dynamic .xcframework │
└─────────┘ └─────────┘ └────────────────────────────────┘
▲
│
│
┌──────────────┐
│ │
│ Dependencies │
│ managed by │
│ CocoaPods │
│ │
└──────────────┘
But when I run the app on the device it is crashing with errors that the Pod dependency cannot be loaded. e.g.:
dyld[49814]: Library not loaded: @rpath/FBAEMKit.framework/FBAEMKit Referenced from: /Users/myUser/Library/Developer/Xcode/DerivedData/App-celtsqxqfqriwohfnqyffousnvru/Build/Products/Debug-iphonesimulator/Framework.framework/Framework
I already did some investigation and it seems that the .frameworks that get extracted by https://github.com/CocoaPods/CocoaPods/blob/5c8d035624d14c76051ab6a11f80271cf702a4a0/lib/cocoapods/generator/copy_xcframework_script.rb are put into a directory called XCFrameworkIntermediates. It seems that in the setup I described they are not correctly picked up by the app Runpath Search Paths from they directory and therefore cannot be found when launching the app. When I manually copy the .framework files on the same level as the binary executable of the app, the app is running correctly.
I also created a sample project to demonstrate the issue: You can find an example project here which demonstrates the issue: https://github.com/alexanderwe/cocoapods-framework-issue.
My question now is:
- Did I do something wrong with the integration of the Pod into my project ?
- Or is this use case not supported by CocoaPods ?
- Is there maybe an issue with the *-xcframeworks.sh script which is generated by CocaoPods ?
- Or is the issue occurring because CocoaPods is not aware of the App target at all and therefore the Runpath Search Paths are not set correctly ?
- Here I have assumed that the framework target is taking care of the run path search paths and not the app target, but I am not sure
- Would it be ok to manually add the
XCFrameworksIntermediatedirectory to theRunPath Search Pathsof the app target ?
Thanks in advance, any answer is highly appreciated :)