Framework can only work on simulator, but not device

僤鯓⒐⒋嵵緔 提交于 2020-01-01 19:15:09

问题


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

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:

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

Target: DTCoreText (iOS)

ARCHS: armv7, arm64

ONLY_ACTIVE_ARCH: NO

VALID_ARCHS: arm64, armv7, armv7s

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

  • Build using simulator:

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.

  • Build using device:

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.

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


回答1:


Problem Solved!!!

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

How to export "fat" Cocoa Touch Framework (for Simulator and Device)?

This post helps me a lot!

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$

As we can see:

  • 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

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

Yes! the ARCHS are "i386 x86_64 armv7 arm64"

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

Done!

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


But

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

Please read this post: Creating iOS/OSX Frameworks: is it necessary to codesign them before distributing to other developers?



来源:https://stackoverflow.com/questions/34615853/framework-can-only-work-on-simulator-but-not-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!