前幾天硬盤壞了。然后換了硬盤,重裝了黑蘋果10.12.1 macOS Sierra,xcode從8.0 ->8.1
公司有兩個項目,一個項目正常。另外一個項目出問題了。我也是納悶了,真機竟然可以,模擬器不行,證書配置了都沒錯。而且,之前都是沒問題的!
報錯如下:
CodeSign /Users/dadong/Library/Developer/Xcode/DerivedData/xxxxxx-eqhusgkiobhnzebfejacuctmahga/Build/Products/Debug-iphonesimulator/xxxxxx.app
cd /Volumes/soft/xxxxxx
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Signing Identity:"-"
/usr/bin/codesign --force --sign - --timestamp=none /Users/dadong/Library/Developer/Xcode/DerivedData/xxxxxx-eqhusgkiobhnzebfejacuctmahga/Build/Products/Debug-iphonesimulator/xxxxxx.app
/Users/dadong/Library/Developer/Xcode/DerivedData/xxxxxx-eqhusgkiobhnzebfejacuctmahga/Build/Products/Debug-iphonesimulator/xxxxxxx.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
我谷歌后發(fā)現有幾個方案:
- 更新cocopods. 有一篇簡書作者也遇到同樣問題,他采用了這個方案解決了。但我的系統(tǒng)剛裝的,所有的環(huán)境,軟件等都是最新的,沒有道理的。然后我還是試過了, clean - delete DerivedData ,重新運行,老樣子
- 在xcode - target - build setting - package - info file里面新增一個空的info plist文件,我沒試過
- 使用
xattr -c帖子是https://forums.developer.apple.com/thread/48905
xattr是什么,在Terminal輸入xattr -help 后發(fā)現,

xattr 說明
不難看出,就是一個可以讀取資源的屬性,刪除屬性,設置屬性的東西。
怎么用?
- 在終端里 ,進入到編譯生成的文件夾,(剛才報錯有提示的)
cd /Users/dadong/Library/Developer/Xcode/DerivedData/xxxxxx-eqhusgkiobhnzebfejacuctmahga/Build/Products/Debug-iphonesimulator/xxxxxx.app - 使用
ls -al@ png列出所有的png圖片的信息,包含屬性

圖片的屬性 有差別
很明顯看到有的圖片,多了com.apple.FinderInfo屬性,應該是當時都是從Finder拉進去的,ps直接生成的。為什么有的沒有,有待驗證
#to do
- 根據論壇所說的,可能就是這個信息導致的,我們嘗試移除它。
- 找到你剛發(fā)現的有問題的圖片,在工程中的路徑,假設我的圖片在xxxxxx/xxxxxxx/images/下,在終端進入此目錄,執(zhí)行
xattr -c *.png,在ls -al@ png會發(fā)現,剛剛的屬性已經消失了就是成功了。 - 同理,如果是appIcon出錯的,就進入到響應的文件夾(asset下),執(zhí)行
xattr -c *.png
- Clean , 最好再手動去刪除下本地編譯生成的文件夾, 比如我的是:"/Users/dadong/Library/Developer/Xcode/DerivedData/xxxxxxx-eqhusgkiobhnzebfejacuctmahga"
- 重新運行。。。搞定了終于。
總結
在本地編譯生成的app文件里,便捷的查看所有的資源文件,利用ls -al@ file_names查看有附帶屬性的文件,然后根據看到的,去自己的真正工程目錄里,找到他們,用命令xattr -c file_names remove掉屬性,搞定。