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.
使用最新版本的cocoa pods(0.36),我可以将用swift编写的cocoa pods嵌入到我的swift项目中。现在,我在这个项目中引入了自己的自定义框架,它也希望依赖于Alamofire。
What I did in order to accomplish that is to select add the pods framework to my framework as dependency:
为了实现这一点,我所做的是选择将pod框架添加到我的框架中作为依赖性:
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".
选择我自己的嵌入式Swift框架(Swift模块)的目标,在“链接框架和库”的“通用”选项卡中,我添加了“Pods.framework”作为“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".
但是,这还不够,因为我自己的swift框架中的类不能“导入Alamofire”,因为它不被认可为“可用框架”。
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.
添加Pods.debug.xcconfig和pod. release。xcconfig文件为我自己的swift框架的目标配置,换句话说,更改构建设置以完成所有更改,cocoa pods对我的iOS应用程序目标的构建设置所做的更改,解决了这个问题。
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.
它现在构建起来没有问题。它在模拟器中运行时没有问题,我自己的嵌入式swift框架成功地使用了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.
显然,并非cocoa pods xcconfig文件中的所有设置都适合添加到我的自定义swift框架的构建设置中。
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...
别的东西……
3 个解决方案
#1
28
I identified the problem. There was simply no pods.framework in the Frameworks/ folder of the embedded framework.
我发现了问题。在嵌入式框架的框架/文件夹中根本没有podcase .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:
我设法解决了这个问题:
- Removing the useless Embed Pods Frameworks to from the build phases
- 从构建阶段删除无用的嵌入pod框架。
- Adding a Copy Files with destination set to Frameworks
- 向框架添加目标集的复制文件
That's it!
就是这样!
#2
4
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.
添加Pods.debug.xcconfig和pod. release。xcconfig文件为我自己的swift框架的目标配置,换句话说,更改构建设置以完成所有更改,cocoa pods对我的iOS应用程序目标的构建设置所做的更改,解决了这个问题。
To do this:
要做到这一点:
-
In your custom embedded framework's Xcode project, click on
File
>New
>File...
>iOS
>Other
>Configuration Settings File
.在自定义嵌入式框架的Xcode项目中,单击文件>新的>文件…> ios>其他>配置设置文件。
-
Do the above twice. You may name the files
Pods.release.xcconfig
andPods.debug.xcconfig
, respectively.做两次以上。你可以把文件命名为Pods.release。xcconfig Pods.debug.xcconfig,分别。
-
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.在项目导航器中,展开Pods Xcode项目>目标支持文件> Pods。您将看到那里有类似的命名为.xcconfig文件。只需将其内容复制到自定义嵌入式Swift框架内同名的文件中。
-
Click your Swift framework's Xcode project file, select the project target (the blue one, not the yellow toolbox one) >
Info
>Configurations
.单击Swift框架的Xcode项目文件,选择项目目标(蓝色的,不是黄色的工具箱)> Info >配置。
-
Expand the
Debug
andRelease
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 thePods.debug
and thePods.release
files that you created previously.展开调试和发布配置。您可能会在Xcode项目下看到两个目标——主框架目标和测试目标。在“基于配置文件”列中,将主目标上的配置文件设置为pod .debug和Pods。释放您先前创建的文件。
And then do @Pasta's answer.
然后做@通心粉的回答。
UPDATE
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).
如果您将自定义的嵌入式Swift框架与其他项目一起使用,那么这个设置将会中断,因为其他项目有不同的.xcconfig设置(Pods的.framework也可能有不同的名称)。
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.
我只在框架中添加了Alamofire作为git子模块。注意:采用git子模块的方式需要您将自定义框架添加到主项目的嵌入式框架中,以及自定义框架内的alamover .framework中。
#3
0
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.
非常感谢分享@通心粉和@Matt Quiros,它解决了我的问题。好了,我想多讲一点我的情况希望这对大家有帮助。
Development environment
开发环境
Xcode Version 9.1 (9B55)
Xcode 9.1版(9 b55)
Deploy iOS version: 10.0
部署iOS版本: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.
所以我正在做一个名为“MyProject”的项目,我用CocoaPod导入“Charts”图书馆。同时,在“MyProject”中还导入了一个私有框架“MyFramework”。这里的问题是,我想在Myframework中使用“Charts”,Xcode一直告诉我“Chart”库是未知的。
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.
我关闭了“MyProject”,打开了“MyFrameWork”和“File”——>“New”——>“File…”。创建两个配置文件,并将它们放在“*”的相同文件夹级别上。xcodeproj”文件。一个配置文件叫做“podmys-frame .debug.xcconfig”,另一个叫做“Pods-MyFramework.release.xcconfig”。(文件名可以是任何东西,但我不确定文件的位置是否重要)。下面是磁盘和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.
现在,关闭“MyFramework”项目并打开“MyProject”项目,在我的Xcode中,文件结构如下所示。在“MyProject”级别下展开“Pods”文件夹。您将看到一些配置文件,将它们的内容复制到您刚刚在“MyFramework”项目“debug”中创建的配置文件中。配置- >调试。配置,释放。配置- > 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.
然后在MyFramewwork的一个" MyViewController "中,我添加了"导入图表"我想在模拟器上试一下…过去了。是的! !然后我在同一个VC中添加了一些代码来创建一个条形图,并成功地在实际设备上运行,并且在屏幕上显示了条形图。然后我尝试了最后一步,@意大利面提到,添加“复制文件”选项来构建“MyProject”的“构建阶段”,它也成功地在真实设备上运行。我又移走了,它仍然有效。
#1
28
I identified the problem. There was simply no pods.framework in the Frameworks/ folder of the embedded framework.
我发现了问题。在嵌入式框架的框架/文件夹中根本没有podcase .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:
我设法解决了这个问题:
- Removing the useless Embed Pods Frameworks to from the build phases
- 从构建阶段删除无用的嵌入pod框架。
- Adding a Copy Files with destination set to Frameworks
- 向框架添加目标集的复制文件
That's it!
就是这样!
#2
4
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.
添加Pods.debug.xcconfig和pod. release。xcconfig文件为我自己的swift框架的目标配置,换句话说,更改构建设置以完成所有更改,cocoa pods对我的iOS应用程序目标的构建设置所做的更改,解决了这个问题。
To do this:
要做到这一点:
-
In your custom embedded framework's Xcode project, click on
File
>New
>File...
>iOS
>Other
>Configuration Settings File
.在自定义嵌入式框架的Xcode项目中,单击文件>新的>文件…> ios>其他>配置设置文件。
-
Do the above twice. You may name the files
Pods.release.xcconfig
andPods.debug.xcconfig
, respectively.做两次以上。你可以把文件命名为Pods.release。xcconfig Pods.debug.xcconfig,分别。
-
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.在项目导航器中,展开Pods Xcode项目>目标支持文件> Pods。您将看到那里有类似的命名为.xcconfig文件。只需将其内容复制到自定义嵌入式Swift框架内同名的文件中。
-
Click your Swift framework's Xcode project file, select the project target (the blue one, not the yellow toolbox one) >
Info
>Configurations
.单击Swift框架的Xcode项目文件,选择项目目标(蓝色的,不是黄色的工具箱)> Info >配置。
-
Expand the
Debug
andRelease
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 thePods.debug
and thePods.release
files that you created previously.展开调试和发布配置。您可能会在Xcode项目下看到两个目标——主框架目标和测试目标。在“基于配置文件”列中,将主目标上的配置文件设置为pod .debug和Pods。释放您先前创建的文件。
And then do @Pasta's answer.
然后做@通心粉的回答。
UPDATE
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).
如果您将自定义的嵌入式Swift框架与其他项目一起使用,那么这个设置将会中断,因为其他项目有不同的.xcconfig设置(Pods的.framework也可能有不同的名称)。
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.
我只在框架中添加了Alamofire作为git子模块。注意:采用git子模块的方式需要您将自定义框架添加到主项目的嵌入式框架中,以及自定义框架内的alamover .framework中。
#3
0
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.
非常感谢分享@通心粉和@Matt Quiros,它解决了我的问题。好了,我想多讲一点我的情况希望这对大家有帮助。
Development environment
开发环境
Xcode Version 9.1 (9B55)
Xcode 9.1版(9 b55)
Deploy iOS version: 10.0
部署iOS版本: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.
所以我正在做一个名为“MyProject”的项目,我用CocoaPod导入“Charts”图书馆。同时,在“MyProject”中还导入了一个私有框架“MyFramework”。这里的问题是,我想在Myframework中使用“Charts”,Xcode一直告诉我“Chart”库是未知的。
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.
我关闭了“MyProject”,打开了“MyFrameWork”和“File”——>“New”——>“File…”。创建两个配置文件,并将它们放在“*”的相同文件夹级别上。xcodeproj”文件。一个配置文件叫做“podmys-frame .debug.xcconfig”,另一个叫做“Pods-MyFramework.release.xcconfig”。(文件名可以是任何东西,但我不确定文件的位置是否重要)。下面是磁盘和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.
现在,关闭“MyFramework”项目并打开“MyProject”项目,在我的Xcode中,文件结构如下所示。在“MyProject”级别下展开“Pods”文件夹。您将看到一些配置文件,将它们的内容复制到您刚刚在“MyFramework”项目“debug”中创建的配置文件中。配置- >调试。配置,释放。配置- > 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.
然后在MyFramewwork的一个" MyViewController "中,我添加了"导入图表"我想在模拟器上试一下…过去了。是的! !然后我在同一个VC中添加了一些代码来创建一个条形图,并成功地在实际设备上运行,并且在屏幕上显示了条形图。然后我尝试了最后一步,@意大利面提到,添加“复制文件”选项来构建“MyProject”的“构建阶段”,它也成功地在真实设备上运行。我又移走了,它仍然有效。