Interface Builder 在使用 Cocoapods 1.0 的框架项目上损坏
Interface Builder broken on Framework projects using Cocoapods 1.0
迁移到 Cocoapods 1.0 none 后,我的 XIB 或使用自定义 IBDesignable
的情节提要在动态框架项目上正确呈现。它失败并出现如下错误:
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
重现步骤:
- 创建一个新的 iOS 框架项目。
- 创建任何依赖项并将其添加到
Podfile
文件。例如:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'FooFramework' do
pod 'Alamofire'
end
- 执行
pod install
并打开 .xcworkspace
文件。
- 创建自定义
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
}
}
- 创建新的 XIB 或故事板并添加自定义视图。
此时XCode将重新编译代码,将无法呈现自定义视图。给出上面提到的错误。
但是,项目编译正确,创建的XIB在执行时成功显示在模拟器中。它仅在 Interface Builder 上的渲染时间失败。
使用 Cocoapods 0.38 或可执行项目的相同过程按预期工作,没有出现错误并且自定义视图正确呈现。
我是否遗漏了 Podfile
中的任何配置参数?它是 Cocoapods 错误吗?有什么解决方法吗?
更新:
尝试使用不同的 Runpath Search Paths
和 Installation Directory
描述 here and 但没有成功。
找到了使用 Cocoapods 0.39 的解决方法,仍然可以正常工作:
pod _0.39.0_ install
似乎 a bug in Cocoapods 由于 Interface Builder 和 Playgrounds 不支持默认作用域。
解决问题之前找到的解决方法:
- 使用
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
迁移到 Cocoapods 1.0 none 后,我的 XIB 或使用自定义 IBDesignable
的情节提要在动态框架项目上正确呈现。它失败并出现如下错误:
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
重现步骤:
- 创建一个新的 iOS 框架项目。
- 创建任何依赖项并将其添加到
Podfile
文件。例如:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'FooFramework' do
pod 'Alamofire'
end
- 执行
pod install
并打开.xcworkspace
文件。 - 创建自定义
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
}
}
- 创建新的 XIB 或故事板并添加自定义视图。
此时XCode将重新编译代码,将无法呈现自定义视图。给出上面提到的错误。
但是,项目编译正确,创建的XIB在执行时成功显示在模拟器中。它仅在 Interface Builder 上的渲染时间失败。
使用 Cocoapods 0.38 或可执行项目的相同过程按预期工作,没有出现错误并且自定义视图正确呈现。
我是否遗漏了 Podfile
中的任何配置参数?它是 Cocoapods 错误吗?有什么解决方法吗?
更新:
尝试使用不同的 Runpath Search Paths
和 Installation Directory
描述 here and
找到了使用 Cocoapods 0.39 的解决方法,仍然可以正常工作:
pod _0.39.0_ install
似乎 a bug in Cocoapods 由于 Interface Builder 和 Playgrounds 不支持默认作用域。
解决问题之前找到的解决方法:
- 使用
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