Reputation: 1460
Using the newest version of cocoa pods (0.36) I am able to embed cocoa pods written in swift (e.g. Alamofire) into my swift project. Now I introduced a custom framework of my own into the project, which also wants to depend on Alamofire.
What I did in order to accomplish that is to select add the pods framework to my framework as dependency:
Select the Target for my own embedded Swift Framework (Swift Module) and in the "General" tab in the "Linked frameworks and libraries" I added "Pods.framework" as "Required".
However, that is not enough in order to compile as the classes in my own swift framework can not "import Alamofire" as it is not recognised as "available framework".
Adding the Pods.debug.xcconfig and the Pods.release.xcconfig file to the Configurations for the target of my own swift framework, in other words changing the build settings to do all the changes, that cocoa pods do to the build settings of my iOS App target, solves the problem.
It now builds without a problem. It also runs without a problem in the Simulator and my own embedded swift framework successfully uses the frameworks added by cocoa pods.
HOWEVER if I run the same on a device, it compiles and installs without a problem, but then crashes with a fatal error on launch:
dyld: Library not loaded: @rpath/Pods.framework/Pods
Referenced from: /private/var/mobile/Containers/Bundle/Application/32D2F1F8-679F-4A5F-8159-28F1C800D0C6/TestingFrameworks.app/Frameworks/mySwiftFramework.framework/mySwiftFramework
Reason: image not found
Apparently not all the settings from the cocoa pods xcconfig file are suited to be added to the build settings of my custom swift framework.
But why does it work in the simulator then? And more important what is the build setting, which I need to correct?
To me it looks like I need to change this build setting:
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods
to something else...
Upvotes: 28
Views: 15302
Reputation: 494
Thanks so much for sharing @Pasta and @Matt Quiros and it solved my problem. So Ok, I just want to share a bit more about my case and hopefully that will be helpful.
Development environment
Xcode Version 9.1 (9B55)
Deploy iOS version: 10.0
Problem:
So I am working on a project named 'MyProject' where I imported 'Charts' library using CocoaPod. The same time, there is also a private framework 'MyFramework' imported in 'MyProject'. Here the problem is that I want to use 'Charts' in 'Myframework' and Xcode keeps telling me that 'Chart' library is unidentified.
Solution:
I closed 'MyProject' and opened 'MyFrameWork' and 'File' -> 'New' -> 'File...'. Create two config files and put them on the same folder level of '*.xcodeproj' file. One config file is called 'Pods-MyFramework.debug.xcconfig' and the other is called 'Pods-MyFramework.release.xcconfig'. (The file name could be anything but I am not sure whether the location of files matters). The following is file structure on disk and in my Xcode.
Now, close 'MyFramework' project and open 'MyProject' project, in my Xcode the file structure is shown below. Expand the 'Pods' folder under 'MyProject' level. You will see some config files, copy their contents to the config files your just created in 'MyFramework' project, debug.config -> debug.config, release.config -> release.config.
Then in one 'MyViewController' in 'MyFramewwork', I added 'import Charts' and just wanted to give it try on simulator and it ... passed. Yeah!! Then I added some code in the same VC to create a bar chart and ran successfully on real device and the bar chart showed on screen. Then I tried last step that @Pasta mentioned that adding 'Copy Files' option to 'Build Phases'of 'MyProject', it also ran successfully on real device. I removed again and it still works.
Upvotes: 2
Reputation: 13511
For any newbies out there like me, this part in the question might confuse you:
Adding the Pods.debug.xcconfig and the Pods.release.xcconfig file to the Configurations for the target of my own swift framework, in other words changing the build settings to do all the changes, that cocoa pods do to the build settings of my iOS App target, solves the problem.
To do this:
In your custom embedded framework's Xcode project, click on File
> New
> File...
> iOS
> Other
> Configuration Settings File
.
Do the above twice. You may name the files Pods.release.xcconfig
and Pods.debug.xcconfig
, respectively.
In your Project navigator, expand the Pods
Xcode project > Target Support Files
> Pods
. You'll see that there are similarly named .xcconfig
files there. Simply copy their contents to the file of the same name inside your custom embedded Swift framework.
Click your Swift framework's Xcode project file, select the project target (the blue one, not the yellow toolbox one) > Info
> Configurations
.
Expand the Debug
and Release
configurations. You'll likely see two targets under your Xcode project--the main framework target, and the test target. In the "Based on Configuration File" column, set the configuration files on the main target to be the Pods.debug
and the Pods.release
files that you created previously.
And then do @Pasta's answer.
If you're using your custom embedded Swift framework with other projects, this setup will break simply because other projects have different .xcconfig
settings (the Pods' .framework
may also be named differently).
I resorted to just adding Alamofire as a git submodule within my framework. NOTE: Going the git submodule
way requires you to add your custom framework to your main project's Embedded Frameworks
, as well as the Alamofire.framework
from inside your custom framework.
Upvotes: 5
Reputation: 1790
I identified the problem. There was simply no pods.framework in the Frameworks/ folder of the embedded framework.
This is due to the fact that the Pods-frameworks.sh don't actually copy things in the right directory.
I managed to fix this problem by:
That's it!
Upvotes: 28