Embedded swift framework with cocoapods - ios

I made a private framework that I want to use in different project. I use Cocoapods with this framework for third parties like AFNetworking, Facebook, or SDWebImage. I use an aggregate to build my framework for simulator and devices architectures.
I can build it, without any problem, but when I add my embedded framework to my new project (wrote in Objective-C), I have this error at the launch:
dyld: Library not loaded: #rpath/AFNetworking.framework/AFNetworking
Referenced from: /private/var/containers/Bundle/Application/2BE49976-94F8-43C3-BBFF-930F11642DDE/MyPhotoApp.app/Frameworks/PhotoLibrary.framework/PhotoLibrary
Reason: image not found
My new project has also Cocoapods with all the required pods of my framework.
The thing I would like, and I can't find how to do it, is to make a framework that depends of Cocoapods, but that does not contains the sources. I would like that the client add itself the necessary pods to its project.
Do you know how I can do that ?
Thank you :)

For Objective-c projects, DONOT uncomment the line use_frameworks!. It is meant only for swift projects. For future reference. :)

Related

Signing sub-framework embedded in root-framework not working (Xcode 11.2.1)

I have a small proof-of-concept app, where I am trying to embed (and sign) a framework (Alamofire) inside of my framework (AequumPOCFramework.framework), however, when I try to deploy to my device, it keeps giving me the error
....not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
If I just try to deploy my own framework, without having Alamofire embedded in it, everything works fine.
The complete error at deploy to my iphone is:
dyld: Library not loaded: #rpath/Alamofire.framework/Alamofire
Referenced from: /private/var/containers/Bundle/Application/EDB697EB-EA15-4301-B4B6-A8FE1F0212BE/PocIOS.app/Frameworks/AequumPOCFramework.framework/AequumPOCFramework
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/EDB697EB-EA15-4301-B4B6-A8FE1F0212BE/PocIOS.app/Frameworks/AequumPOCFramework.framework/Frameworks/Alamofire.framework/Alamofire: code signature in (/private/var/containers/Bundle/Application/EDB697EB-EA15-4301-B4B6-A8FE1F0212BE/PocIOS.app/Frameworks/AequumPOCFramework.framework/Frameworks/Alamofire.framework/Alamofire) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
What am I doing wrong?
Nested frameworks are not supported on iOS (see technotes). The only legit solution at the moment is to link "embedded" frameworks directly to a hosting app.
*XCFramework is mainly an aggregation of platform specific binaries and has nothing to do with embedding frameworks unfortunately.
You gotta embed Alamofire to your project, too.
For example, you are using Carthage and the Cartfile of your framework has Alamofire library. You gotta use the same Carfile for your main app, too. Also, you gotta perform other Carthage actions(linking library, adding run script) for the main app.
In case anyone looking solution for dylib for this error:
dylib not valid for use in process: mapped file has no cdhash
Check Code sign on copy in Build Phases -> Copy to $(BUILT_PRODUCTS_DIR)/$FRAMEWORKS_FOLDER_PATH
As Berec pointed out embedding frameworks in a framework is not supported. But there is an other way. You can statically link all the dependencies of your library, so in the final framework the binary will also contain the code of its dependencies.
If you are using CocoaPods and the name of the framework is aFramework you can do:
target 'aFramework' do
pod 'Alamofire', :linkage => :static
end
Then you can use the created aFramework.framework in a application target that does not have the Alamofire framework, since the code will be "embedded" in the aFramework's binary.

How to build Cocoa touch framework which use third party lib as cocoa pod?

I'm a iOS developer and want to build a distributed framework which use pods to integrate third party lib in framework project. Pods like SVProgressHUD and socket.io-client-swift.
I want to know what is the best way to build this kind of frameworks. Is there any tutorial given online which gives all the instructions.
I tried building a framework in above structure and it complies fine but when I'm importing this framework in other project getting errors:
dyld: Library not loaded: #rpath/Framework.framework/Framework
Referenced from:
/var/containers/Bundle/Application/73A8E170-4FE5-4CFF-B52E-C42099F32F9C/Framework.app/Framework
Reason: image not found
Can anyone help me. Thanks in Advance!
All you need to do is set the third party frameworks you are using for e.g:- socket.io-client-swift as Optional instead of Required under Link binary with Libraries in build Phases section. That's all. try it again and it will run as expected.

Cocoapods inside iOS framework not working

I'm trying to create a framework with some features of my App, which depends on Cocoapods for its dependencies.
The framework is compiling OK, but when added into another project, it crashes with this trace
Library not loaded: #rpath/AFNetworking.framework/AFNetworking
Referenced from: /private/var/containers/Bundle/Application/BA3917FD-FCF1-491B-90AF-86AFDCD7FF80/BMNPoC.app/Frameworks/myframework.framework/myframework
Reason: image not found
When searching on product folder I see my framework and the pod framework with AFNetworking in this case (so 3 separated frameworks). I guess those frameworks aren't being embed into MyFramework. How can I achieve this? Here's a link to a demo project https://www.dropbox.com/s/p9dbx9xy61twcoa/MyFramework.zip?dl=0

Xcode: create Framework with pod dependecies

I create a framework that use AFNetworking (installed with pod).
I can import this framework on my project and I can use all classes/methods that I exposed, so project compile.
When I try to run project on simulator, I obtain this error:
dyld: Library not loaded: #rpath/AFNetworking.framework/AFNetworking
Referenced from:
/Users/.../Library/Developer/CoreSimulator/Devices/F56F98F0-2AE0-4C87-AC9A-6E3B449762D1/data/Containers/Bundle/Application/BFA5359F-8FCE-4402-8487-CD9C002CB673/MyProject.app/Frameworks/MyFramework.framework/MyFramework
Reason: image not found
I already included 'MyFramework' under:
Build phases -> Embed Frameworks
I suppose I missing something on building Frameworks, but I can find out what! I already seen this unanswered question.
Who can I use MyFramework without installing Pod on MyProject again?
It is really delayed, for this issue but I have got my project working. It might not be the best way but it works. I am putting it here for future reference.
I wanted to do it without using Pods in the main project. The reasoning is, we are bundling our SDK into a framework.
So essentially, the first step I took was to get the framework project bundling without using the workspace. I just dragged the Pods project into the framework project.
Then I added the frameworks the the pods project creates and add them to my framework. I set them to optional and code sign. You can see them in the picture of where I added them under the build phases.
Then add them to your main project. not the framework the normal way by adding the project and or the framework. Then add it to the Embedded binaries and Linked Frameworks.
If it helps anyone, the solution mentioned by #ArtyomDevyatov does work. The trick is that you have to add 's.dependency' in podspec file.

Cocoa Touch Framework Dependencies

I'm trying to create a Cocoa Touch Framework. To create a framework is not a problem, I used this tutorial and it is good.
I need to use third party libraries inside: like openssl, XLForm, AFNetworking. I know that it is not correct to include them in my framework, I need to create a dependencies, but I can't find how to do this.
Moreover is it possible to use pods in my framework and just make dependencies to these libs. So user which will include my framework to his project will need just install these pods.
It seems that I found solution.
Thanks to #Droppy and thanks to this question.
What I did: I just installed pods to my Framework project but used this use_frameworks! key.
Then I dragged my Framework to my Project and installed pods there, also with same key, otherwise (when pod wasn't installed in my Project) I was getting error like:
dyld: Library not loaded: #rpath/XLForm.framework/XLForm...
I used XLForm inside my Framework.

Resources