Xcode 8在 iOS 9.2及以下版本上构建崩溃

当我用 Xcode 8 GM Seed 构建我的应用程序并在设备或模拟器之下的 iOS 9.2上运行它时,我会在应用程序启动期间或应用程序启动后几秒钟内出现奇怪的 EXC _ BAD _ ACCESS 崩溃。崩溃总是发生在不同的地方(添加子视图、 [UIImage imageNamed:]、应用程序委托的主方法等)。当我在 iOS 9.3 + 或10上运行它时,我不会遇到这些崩溃,当我用 Xcode 7运行 建造并在 iOS 9.2及以下版本上运行时,我也不会遇到这些崩溃。其他人有过类似的经历吗?这是 Xcode 8的已知问题吗?

16646 次浏览

same issue.

I'm not sure if this is a bug but here is my solution : make sure your image assets without Adobe RGB (1998) colorspace

in xcode

See the accepted answer https://forums.developer.apple.com/thread/60919

You can save 16-bit assets as 8-bit ones with Preview.app

How to resolve "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 8 or earlier."

With Xcode 8 GM, this error will occur if you include 16-bit or P3 assets in an app submission targeting iOS releases earlier then iOS 9.3. If your app requires wide color functionality you must change your Deployment Target to iOS 9.3 or later. If your app does not require wide color functionality and you wish to deploy it to older iOS versions then you should replace all 16-bit or P3 assets with 8-bit sRGB assets. You can find 16-bit or P3 assets by running “assetutil” on the asset catalog named in the error message from iTunes Connect. The following steps outline the process:

  1. Create an Inspectable .ipa file. In the Xcode Organizer (Xcode->Window->Organizer), select an archive to inspect, click “Export...", and choose "Export for Enterprise or Ad-Hoc Deployment". This will create a local copy of the .ipa file for your app.

  2. Locate that .ipa file and change its the extension to .zip.

  3. Expand the .zip file. This will produce a Payload folder containing your .app bundle.

  4. Open a terminal and change the working directory to the top level of your .app bundle cd path/to/Payload/your.app

  5. Use the find tool to locate Assets.car files in your .app bundle as shown below: find . -name 'Assets.car'

  6. Use the assetutil tool to find any 16-bit or P3 assets, in each Assets.car your application has as shown below. : sudo xcrun --sdk iphoneos assetutil --info /path/to/a/Assets.car > /tmp/Assets.json

  7. Examine the resulting /tmp/Assets.json and look for any contents containing “DisplayGamut": “P3” and its associated “Name". This will be the name of your imageset containing one or more 16-bit or P3 assets.

  8. Replace those assets with 8-bit / sRGB assets, then rebuild your app.

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.

I hope this bash script may help you. Input argument is directory than contains all xcassets of your project. This script will set sRGB profile to all pngs. It helped me:)

#!/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 "------------------------------"

I was able to reproduce the problem and it does seem related to images in Asset Catalog. Filed a bug with Apple (with attached sample project)

Apple Bug Reporter: 28371396

Set the iOS Deployment Target inside Info of your project and all the targets to the same value.

In my case my Project was set to iOS 9.1 and the Target was set to iOS 8.0 and was crashing on Simulator with iOS 8.4

Now it's working perfectly.

PS.: Clean the project before running again.

edited script to convert png files to correct format in whole project and with white spaces:

#!/bin/bash
DIRECTORY=$1
echo "------------------------------"
echo "Passed Resources with xcassets folder argument is <$DIRECTORY>"
echo "------------------------------"
echo "Processing asset:"


find "$DIRECTORY" -name '*png' -print0 | while read -d $'\0' file;
do
echo "---------$file"
sips -m "/System/Library/Colorsync/Profiles/sRGB Profile.icc" "$file" --out "$file"
done


echo "------------------------------"
echo "script successfully finished"
echo "------------------------------"

Adding for anyone else with a similar problem...

App was crashing on iOS 9.0 - iOS 9.2 on what seemed random / around Storyboard transitions / around setting an UIImage(name...).. Found this thread: (https://forums.developer.apple.com/thread/61643)

If your app is targeting iOS 8.4, it will crash on iOS 9.0 - 9.2 in Xcode 8.. something to do with xcassets. Setting the deployment target to 8.2 or below ( I used 8.0) fixed it for me. No kidding. Worst bug ever.

Although question has been already answered, accepeted solution doesn't work for me, as I didn't have any 16b/ch assets.

I found that issue appeared for assets which were compressed using lzfse algorithm (you can find information about compression extracting info from Assets.car using assetutil). Unfortunately Xcode IDE doesn't allow developers to change compression algorithm, however you can do that by compiling assets manually and lowering deployment target in actool command.

tl;dr;

  1. Archive
  2. Unzip ipa
  3. Compile assets - You can find asset compiler command for your project generated by xcode by checking archive logs in Xcode report navigator

Example command:

xcrun actool --output-format human-readable-text --notices --warnings --minimum-deployment-target 8.0 --output-partial-info-plist info_partial.plist --app-icon AppIcon --launch-image LaunchImage --enable-on-demand-resources YES --sticker-pack-identifier-prefix {bundle_id}.sticker-pack --target-device iphone --target-device ipad --platform iphoneos --product-type com.apple.product-type.application --compile #{path_to_directory_containing_Assets_car} Assets/Assets.xcassets

  1. Zip it.
  2. Resign