在使用Cocoapods 1.0的框架项目上破坏了Interface Builder
在迁移到Cocoapods 1.0后,我的XIB或使用自定义IBDesignable
Storyboard都IBDesignable
在dynamic框架项目上正确呈现。 它失败,像这样的错误:
file:///Users/xxxxx/workspace/FooFramework/FooFramework/View.xib: error: IB Designables: Failed to update auto layout status: dlopen(FooFramework.framework, 1): Library not loaded: @rpath/Alamofire.framework/Alamofire Referenced from: FooFramework.framework Reason: image not found file:///Users/xxxxx/workspace/FooFramework/FooFramework/View.xib: error: IB Designables: Failed to render instance of CustomView: dlopen(FooFramework.framework, 1): Library not loaded: @rpath/Alamofire.framework/Alamofire Referenced from: FooFramework.framework Reason: image not found
重现步骤:
- 创build一个新的iOS框架项目。
- 创build并添加任何依赖到
Podfile
文件。 例如:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! target 'FooFramework' do pod 'Alamofire' end
- 执行
pod install
并打开.xcworkspace
文件。 - 创build一个自定义的
IBDesignable
UIView
子类。 例如:
import UIKit @IBDesignable class CustomView: UIView { override init(frame: CGRect) { super.init(frame: frame) layer.cornerRadius = 10 } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) layer.cornerRadius = 10 } }
- 创build一个新的XIB或故事板并添加自定义视图。
此时XCode将重新编译代码,并将无法呈现自定义视图。 给出上面提到的错误。
但是,项目编译正确,并且创build的XIB在执行时成功显示在模拟器中。 它只在Interface Builder上呈现时间失败。
使用Cocoapods 0.38或可执行项目相同的过程按预期方式工作,没有错误,并自定义视图呈现正确。
我是否缺lessPodfile
中的任何configuration参数? 这是一个Cocoapods的错误? 有没有解决办法?
更新 :
尝试使用不同的Runpath Search Paths
和Installation Directory
像这里和这里所描述的没有运气。
使用Cocoapods 0.39find一个解决方法,仍然没有问题:
pod _0.39.0_ install
由于默认的作用域不被Interface Builder和Playgrounds支持,这似乎是Cocoapods中的一个bug 。
find解决方法,直到它被修复:
- 使用
pod _0.39.0_ install
回退到0.39。 - 将以下代码添加到
Podfile
:
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR' end end end