1. 程式人生 > >舊專案適配 iOS9 時 .dylib 系統庫檔案的連結報錯的問題處理

舊專案適配 iOS9 時 .dylib 系統庫檔案的連結報錯的問題處理

今天將公司的專案改用 Xcode7 開發,剛開啟專案就有醒目的四個地方爆紅


但是在模擬器環境的依舊能夠正常的執行,一旦連線到真機(非 iOS9 系統)就提示有兩個庫檔案找不到,如下所示:


難道 iOS9 蘋果的庫檔案也發生了相應的變化?檢視 8.4 與 9 的模擬器中的庫檔案存放資料夾發現果真蘋果在 iOS9  中將庫檔案的字尾由 .dylib 更改為了 .tbd :


那麼將對應的連結庫直接更改為 iOS9 的新檔案?對應的更改後發現在 Xcode7 中正常,可是將專案執行在 Xcode6.4 中報錯那是一片紅啊,並且在非 iOS9 系統的真機上依舊編譯通不過有問題。

在網上查詢相應的資料,也有朋友遇到了類似的問題,借鑑一位大神提出的解決方案如下(思路是將庫檔案改為連結本地的以便與 iOS 系統版本脫離關係):

The Problem
As 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 missing
My (successful) Work Around
Sorry, no tl;dr for this part
1) 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/