Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

ios - Swift framework depending on cocoa pod

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Removing the useless Embed Pods Frameworks to from the build phases
  2. Adding a Copy Files with destination set to Frameworks

enter image description here

That's it!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...