旧项目适配 iOS9 时 .dylib 系统库文件的链接报错的问题处理

来源:互联网 发布:阿里云助手 编辑:程序博客网 时间:2024/05/29 04:06

今天将公司的项目改用 Xcode7 开发,刚打开项目就有醒目的四个地方爆红



但是在模拟器环境的依旧能够正常的运行,一旦连接到真机(非 iOS9 系统)就提示有两个库文件找不到,如下所示:







难道 iOS9 苹果的库文件也发生了相应的变化?查看 8.4 与 9 的模拟器中的库文件存放文件夹发现果真苹果在 iOS9  中将库文件的后缀由 .dylib 更改为了 .tbd :





























那么将对应的链接库直接更改为 iOS9 的新文件?对应的更改后发现在 Xcode7 中正常,可是将项目运行在 Xcode6.4 中报错那是一片红啊,并且在非 iOS9 系统的真机上依旧编译通不过有问题。

在网上查找相应的资料,也有朋友遇到了类似的问题,借鉴一位大神提出的解决方案如下(思路是将库文件改为链接本地的以便与 iOS 系统版本脱离关系):

The ProblemAs all wonderful iOS and OS X developers have found in Xcode 7, dynamic libraries are no longer xx.dylib. They are now xx.tbd. According to an Apple staff member, the .tbd files are new "text-based stub libraries", that provide a much more compact version of the stub libraries for use in the SDK, and help to significantly reduce its download size. My best assumption is that this is part of the "App Thinning" and how they are able to reduce iOS 9 and OS X by so much.Currently, if you updated your app to iOS 9/ OS X 10.11 you find it is have many errors and a missing library. When importing the new .tbd, it does not act correct. This is a known bug. Apple has their "official workaround", and you may find it here, but you will find it doesn't work unless you are using an uncompressed library (such as sqlite3), and even then, I did not fully test it as none of my apps use them.tl;dr: update apps iOS9/ OS X 10.11 and dynamic libraries are missingMy (successful) Work AroundSorry, no tl;dr for this part1) Delete the reference to the library in "Build Phases" under "Linked Frameworks and Libraries" (as you would to remove it normally), remove reference in the Navigator as well (keeps your files clean)2) Under "Linked Frameworks and Libraries", click "+"3) Click "Add Other"4) Press "Shift" + "Command" + "G"5) Replace contents with "/usr/lib" and click "Go"6) Scroll through the folder to find your library, select it, and click "Open" to add it to your project. This will add the .dylib (or uncompressed library) to your project.All previous links in your code will start working again! No need for extra code, or updating anything in your build settings or build phases to accommodate the change.| If anyone had problems with the above, please comment!|

最后将本地的  /usr/lib 文件夹下有问题的库文件重新链接进项目,Xcode6.4 与 Xcode7 均编译运行正常通过!


参考链接

https://www.reddit.com/r/iOSProgramming/comments/39rcby/ios_9_os_x_1011_xcode_7_development_with_dynamic/

0 0