Swift Framework 构建针对设备失败,但针对模拟器失败 [英] Swift Framework build fails for device but not for simulator

查看:15
本文介绍了Swift Framework 构建针对设备失败,但针对模拟器失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想法为什么构建会成功用于模拟器而不是设备?

Any ideas why a build would succeed for simulator but not a device?

我创建了一个 Cocoa 框架,并且能够将它添加到一个新的单页应用程序项目中,并调用框架中定义的方法.只要我将模拟器选为构建目标而不是设备,就可以构建项目.我没有试过运行它,只是构建.我使用的是 Swift 3 和 XCode 8.1.

I created a Cocoa framework and was able to add it to a new single-page application project, and call the methods defined in the framework. The project built as long as I had a simulator selected as the build target and not a device. I have not tried running it, only building. I'm using Swift 3 and XCode 8.1.

我收到 Use of unresolved identifier 错误.

推荐答案

听起来您构建的框架是为模拟器而非设备构建的.当链接器尝试为设备链接应用程序时,它找不到为该设备构建的框架.

It sounds like you built the framework for a simulator and not for a device. When the linker is trying to link the application for a device, it doesn't find the framework built for that device.

两种方法如下.

1) 在构建框架时,设置适合设备的活动方案(Xcode 的左上角区域).然后,在为设备构建应用程序之前,转到应用程序的构建设置并将框架的位置添加到框架搜索路径.确保选择正确的二进制文件!例如,在为 iOS 模拟器构建时,框架的调试二进制文件将位于名为 Build/Products/Debug-iphonesimulator 的目录中.

1) When building the framework, set the active scheme appropriate for the device (upper left area in Xcode). Then, before building the application for the device, go to Build Settings for the app and add the framework's location to Framework Search Paths. Make sure you pick the right binary! For example, when building for the iOS simulator, a debug binary of the framework is going to be in a directory called Build/Products/Debug-iphonesimulator.

使用这种方法,您还需要将框架添加到应用的复制文件构建阶段,将目标指定为框架.

With this approach you also need to add the framework to the Copy Files build phase of your app, specifying Destination as Frameworks.

2) 将框架嵌入到应用程序中,使其成为应用程序的依赖项,并在应用程序的构建阶段设置应用程序与框架链接.见

2) Embed the framework into the application, make it a dependency of the app, and set up the application to link with the framework in the app's Build Phases. See

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

关于嵌入框架和其他有用的框架相关信息.完成此操作的一种便捷方法是转到应用程序目标的常规"选项卡,并在嵌入式​​二进制文件"部分中添加框架.

about embedding a framework and for other useful framework-related info. A convenient way of accomplishing this is to go to the General tab of your application target and add the framework in the Embedded Binaries section.

或者,如果您在创建应用程序后创建您的框架,您可以要求 Xcode 将框架嵌入到应用程序中.

Alternatively, if you create your framework after creating the application, you can ask Xcode to embed the framework into the app.

这篇关于Swift Framework 构建针对设备失败,但针对模拟器失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆