框架只能在模拟器上工作,不能在设备上工作 [英] Framework can only work on simulator, but not device

查看:40
本文介绍了框架只能在模拟器上工作,不能在设备上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Xcode 7.2 (7C68) 版.

I'm using Xcode Version 7.2 (7C68).

我在构建 DTCoreText 项目作为框架后遇到了一个问题.DTCoreText.framework 在 ios 模拟器上运行良好,但是当我想在设备上测试它时,出现了以下问题:

I met a problem after I build DTCoreText project as framework. DTCoreText.framework works fine on ios simulator, but when i want to test it on device, the following problem showed up:

我已经检查了最新的 DTCoreText-1.6.17 中的构建设置 项目:

I've checked the build settings in the latest DTCoreText-1.6.17 project:

目标:DTCoreText (iOS)

ARCHS:armv7、arm64

ONLY_ACTIVE_ARCH:

ONLY_ACTIVE_ARCH: NO

VALID_ARCHS:arm64、armv7、armv7s

VALID_ARCHS: arm64, armv7, armv7s

我觉得这些设置没问题.比我为分析而构建"按 Shift+CMD+i.

I think these settings are OK. Than I "Build for Profiling" by pressing Shift+CMD+i.

  • 使用模拟器构建:

我注意到我刚刚用于构建的当前设备是模拟器(iPhone 6 Plus).我在下面找到了 DTCoreText.frameworkRelease-iphonesimulator 文件夹.通过这样做,DTCoreText.framework 只能在使用 iphone 模拟器时正常工作,但是不是在真实设备上.

I noticed the current device i just used for building is Simulator (iPhone 6 Plus). And I find the DTCoreText.framework under the Release-iphonesimulator folder. by doing this, the DTCoreText.framework only works fine when using iphone simulator, but not on real device.

  • 使用设备构建:

比我试图用相同的构建重建 DTCoreText.framework设置,但使用通用 iOS 设备"真实设备"(例如:iPhone 6s)".我得到了 DTCoreText.framework 下Release-iphoneos 文件夹.通过这样做,DTCoreText.framework 仅在使用真实设备时才能正常工作,而不能在 iphone 模拟器上运行.

Than I tried to rebuild DTCoreText.framework with the same build settings, but using "Generic iOS Device" or "Real Device (eg: iPhone 6s)". I got the DTCoreText.framework under Release-iphoneos folder. By doing this, the DTCoreText.framework only works fine when using real device, but not on iphone simulator.

我不知道为什么会这样.如何为模拟器和真机构建DTCoreText.framework?

I don't know why it is happening. How to build DTCoreText.framework for both simulator and real device?

推荐答案

问题解决!!!

我需要的是为i386 x86_64 armv7 arm64"制作一个FAT"框架!

What I need is making a "FAT" Framework for "i386 x86_64 armv7 arm64"!

如何导出fat"Cocoa Touch Framework(用于模拟器和设备)?

这篇文章对我帮助很大!

This post helps me a lot!

只需使用lipo -info"命令来检查ARCHS,例如:

Just use "lipo -info" command to CHECK the ARCHS, for example:

admins-MacBook-Pro:~ admin$
admins-MacBook-Pro:~ admin$ lipo -info /Users/admin/Desktop/DT/device/DTCoreText.framework/DTCoreText
Architectures in the fat file: /Users/admin/Desktop/DT/device/DTCoreText.framework/DTCoreText are: armv7 arm64
admins-MacBook-Pro:~ admin$
admins-MacBook-Pro:~ admin$ lipo -info /Users/admin/Desktop/DT/simulator/DTCoreText.framework/DTCoreText
Architectures in the fat file: /Users/admin/Desktop/DT/simulator/DTCoreText.framework/DTCoreText are: i386 x86_64
admins-MacBook-Pro:~ admin$

正如我们所见:

  • 使用模拟器构建时,xcode 使用 ARCHS "i386, x86_64" 生成框架
  • 使用设备构建时,xcode 使用 ARCHS "armv7, arm64" 生成框架
  • When build using simulator, xcode generate framework using ARCHS "i386, x86_64"
  • When build using device, xcode generate framework using ARCHS "armv7, arm64"

要将两个框架组合在一起,请使用以下命令,例如:

To Combine the two framework together, use the following command, for example:

admins-MacBook-Pro:~ admin$ lipo -create /Users/admin/Desktop/DT/device/DTCoreText.framework/DTCoreText /Users/admin/Desktop/DT/simulator/DTCoreText.framework/DTCoreText -output /Users/admin/Desktop/DTCoreText

现在您可以在桌面上找到DTCoreText"二进制文件.用lipo cmd再次检查一下:

Now you can find the "DTCoreText" binary file on your desktop. Use lipo cmd to check it again:

admins-MacBook-Pro:~ admin$ lipo -info /Users/admin/Desktop/DTCoreText
Architectures in the fat file: /Users/admin/Desktop/DTCoreText are: i386 x86_64 armv7 arm64

是的!ARCHS 是 i386 x86_64 armv7 arm64"

Yes! the ARCHS are "i386 x86_64 armv7 arm64"

将DTCoreText"二进制文件放入 DTCoreText.framework 并替换旧的!

Put the "DTCoreText" binary file inside DTCoreText.framework and replace the old one!

完成!

现在我们应该可以同时使用设备和模拟器的框架了!

Now we should able to use the framework for both device and simulator!

但是

这只是为了方便测试,如果您想将您的应用提交到应用商店.苹果会拒绝,因为包含模拟器切片的iOS框架无法提交到App Store".

This is only for the convenience of testing purpose, If you want to submit your app to app store. apple will reject it due to "iOS frameworks containing simulator slices can't be submitted to the App Store".

请阅读这篇文章:创建 iOS/OSX 框架:是吗在分发给其他开发者之前是否需要对它们进行协同设计?

这篇关于框架只能在模拟器上工作,不能在设备上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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