iOS10+Xcode8 + iOS8 -- Xcode8的assets問(wèn)題導(dǎo)致運(yùn)行iOS8崩潰的解決方案

iOS 10 出來(lái)了,項(xiàng)目需要適配,更新Xode8 后,項(xiàng)目運(yùn)行iOS 8.4 真機(jī)時(shí),出現(xiàn)莫名其妙崩潰的問(wèn)題。在網(wǎng)上尋求解決方案時(shí)發(fā)現(xiàn)了這篇博文-- @ian博客 Xcode8的assets問(wèn)題導(dǎo)致運(yùn)行iOS8崩潰的解決方案

看完文章后,發(fā)現(xiàn)操作有點(diǎn)復(fù)雜。點(diǎn)開(kāi)博文文獻(xiàn)《Xcode 8 build crash on iOS 9.2 and below》
!!!發(fā)現(xiàn)了這個(gè)

 Update: If your Deployment Target is set to either 8.3 or 8.4 and you have an asset catalog then you will 
receive this same error message, even if you do not actually have 16-bit or P3 assets. In this case you will 
either need to lower your Deployment Target to 8.2, or move it up to 9.x.

結(jié)合項(xiàng)目另一個(gè)端Deployment Target 為8.0運(yùn)行沒(méi)問(wèn)題,將發(fā)現(xiàn)此問(wèn)題的端的Deployment Target 從8.4改為8.0 后運(yùn)行就沒(méi)問(wèn)題了,簡(jiǎn)單快速。<( ̄3 ̄)> Xcode更新真是...漲姿勢(shì)。

博文如下:

一、前言

如果你剛剛升級(jí)了Xcode8,而你的項(xiàng)目的Deployment Target是iOS 9.3以下,運(yùn)行iOS8的時(shí)候過(guò)了幾十秒后crash到main函數(shù),出現(xiàn)EXC_BAD_ACCESS,或者崩潰到imageNamed:,或者每次編譯運(yùn)行隨機(jī)崩潰到某個(gè)地方。那么恭喜你,你讀完這個(gè)文章你可能就解決了。

二、崩潰原因

在Xcode8中,如果你的圖片資源文件里有16位圖或者圖片顯示模式為P3,并且Deployment Target是iOS9.3以下的就會(huì)出現(xiàn)這個(gè)問(wèn)題。(話(huà)說(shuō)我公司的項(xiàng)目里面就出現(xiàn)了一個(gè)小按鈕,導(dǎo)致了這次崩潰,不知道設(shè)計(jì)師是怎么弄出來(lái)的這個(gè)特殊圖片…)如果你的App需要支持wide color functionality,那你就必須設(shè)置Deployment Target為iOS9.3以上。如果你的APP不需要支持wide color functionality并且你希望兼容iOS老版本,那么你需要將所有16-bit or P3 assets的圖片轉(zhuǎn)換為8-bit sRGB assets

三、定位到問(wèn)題圖片

1.打一個(gè)ipa包,解壓你的應(yīng)用的ipa包,進(jìn)入到你應(yīng)用的Playload文件夾。

// 在終端中打開(kāi) (補(bǔ)充)
cd ../Playload

2.用find命令定位到Assets.car文件

find . -name 'Assets.car'

3.使用 assetutil 命令導(dǎo)出圖片的信息存儲(chǔ)到Assets.json文件中

sudo xcrun --sdk iphoneos assetutil --info /path/to/a/Assets.car > /tmp/Assets.json

4.打開(kāi)剛才生成的Assets.json文件,查找含有”DisplayGamut” : “P3”, “Encoding” : “ARGB-16″的內(nèi)容。這個(gè)對(duì)應(yīng)的Name就是出現(xiàn)問(wèn)題的圖片了。

 //  打開(kāi)json文件 (補(bǔ)充)
open /tmp/Assets.json 
  {
    "SizeClass Vertical" : "universal",
    "Graphics" : "GLES2,0",
    "Name" : "ianisme.com",
    "Scale" : 2,
    "Idiom" : "universal",
    "Memory" : "512MB",
    "LayoutDirection" : "0 - Horizontal",
    "DisplayGamut" : "P3",
    "Encoding" : "ARGB-16",
    "SizeClass Horizontal" : "universal",
    "Image Type" : "kCoreThemeOnePartScale",
    "AssetType" : "Image",
    "Subtype" : 0,
    "EdgeInsets" : "top:0 left:0 bottom:0 right:0"
  },

四、轉(zhuǎn)換圖片為8-bit sRGB assets格式

我們找到這個(gè)圖片,然后CMD+i 查看這個(gè)圖片的信息,我們發(fā)現(xiàn)我這個(gè)出問(wèn)題的文件的顏色描述文件有問(wèn)題,和別的圖片文件不一樣。
出問(wèn)題的圖片:

別的圖片

1.方法一(單個(gè)處理問(wèn)題圖片):

下面我們使用ColorSync實(shí)用工具將這個(gè)描述文件修改下

xcode8crash3

指派它的描述文件為sRGB IEC61966-2.1,保存。

xcode8crash4

再次編譯運(yùn)行我們的APP,發(fā)現(xiàn)問(wèn)題解決了!

2.方法二(暴力處理所有圖片):

這里我們使用bash script直接處理所有圖片為正確格式,這樣我們就不用去定位是哪個(gè)圖片的問(wèn)題了,或許更方便一些。

#!/bin/bash
DIRECTORY=$1
echo "------------------------------"
echo "Passed Resources with xcassets folder argument is <$DIRECTORY>"
echo "------------------------------"
echo "Processing asset:"
XSAASSETSD="$(find "$DIRECTORY" -name '*.xcassets')"
for xcasset in $XSAASSETSD
do
    echo "---$xcasset"
    IMAGESETS="$(find "$xcasset" -name '*.imageset')"
    for imageset in $IMAGESETS
    do
        echo "------$imageset"
        FILES="$(find "$imageset" -name '*.png')"
        for file in $FILES 
        do
            echo "---------$file"
            sips -m "/System/Library/Colorsync/Profiles/sRGB Profile.icc" $file --out $file
        done
    done
done
echo "------------------------------"
echo "script successfully finished"
echo "------------------------------"

五、總結(jié)

出現(xiàn)這個(gè)問(wèn)題真的很蛋疼,但是最后終于解決了。每一次Apple編譯器的升級(jí)都會(huì)伴隨著大大小小的問(wèn)題,只要我們懷著一顆不拋棄不放棄的決心,最后一定可以攻克難題。最后要感謝公司同事的指導(dǎo),還要感謝以下參考文獻(xiàn)的作者們,沒(méi)有他們的實(shí)踐,這個(gè)問(wèn)題或許困擾更久。

參考文獻(xiàn):

1.《ITMS-90682: can’t contain 16-bit or P3 assets if the app supports iOS 8 or earlier》
2.《Xcode 8 build crash on iOS 9.2 and below》
3.《ERROR ITMS-90682: Invalid Bundle – The asset catalog at ‘Payload/XXXXX/Assets.car’ can’t contain 16-bit or P3 assets if the app supports iOS 9.3 or earlier. 》
4.《Assets.car can’t contain 16-bit or P3 assets if the app supports iOS 8 or earlier?》
5.《Community bug reports》

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容