Xcode 8 build crash on iOS 9.2 and below
Asked Answered
C

8

86

When I build my app with Xcode 8 GM Seed and run it on an iOS 9.2 below device OR simulator, I get strange EXC_BAD_ACCESS crashes during app startup or a few seconds after the app launched. The crash always happens in a different spot (adding a subview, [UIImage imageNamed:], app delegate's main method etc). I don't get those crashes when I run it on iOS 9.3+ or 10 and I don't get them when I build with Xcode 7 and run on iOS 9.2 and below. Has anyone else experiences something similar? Is this a known issue with Xcode 8?

Childers answered 9/9, 2016 at 5:15 Comment(8)
First, reset content of simulator. and try again.Euton
Were you able to resolve your problem? We're having it too.Metope
Can you file a new bug at bugreport.apple.com, and attach the sample project and crash logs so we can investigate?Spartacus
@QuinnTaylor - I've filed a bug report with attached project (reproduced 100% for me in simulator) at bugreport.apple.com #28371396. Thank you for looking into this!Boss
@EvtimGeorgiev Thanks! It's a duplicate of an iOS bug related to P3 .png images, and should be fixed in the iOS 10.1 beta SDK included in Xcode 8.1 beta, which was released today. Can you try building with that?Spartacus
@QuinnTaylor I downloaded the Xcode 8.1 beta and compiled my application with the same. I didn't see any crash for application running on device and simulator with iOS 9.2. I still need to test on iOS 8.Ripe
@QuinnTaylor I ran into the same issue and it looked as if it was fixed in Xcode 8.1. But now I see the same issue in crash reports in Crashlytics again. It was the first beta of our app built with Xcode 8.1: iPhone 4S and iPod touch 5G users crash on iOS 9.0.x and 8.x. When building with Xcode 7, everything is fine.Cirrostratus
Can this crashes occurs with images downloaded from internet? I've already fixed my app assets but suddenly is crashing in iOS from 9.0 to 9.2.1.Ratel
S
56

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.

Septal answered 12/9, 2016 at 15:25 Comment(10)
How is this related to EXC_BAD_ACCESS?Metope
Please don't duplicate answers. Instead, flag questions as duplicates.Snowdrop
Thank you man! You saved a ton of time for me with this answer! )Menefee
In my project (deployment target is 8.0) there is no P3 assets still i am getting crash on app or randomly at any place with xcode 8. All assets are of 8-bit / sRGB. Did anyone still facing this same issueAceous
@Aceous we are facing same issue. Have you found solution yet?Customary
@Roman Truba No i have not found any solution still looking to solve the issue.Aceous
This solution seems to be the best. The error is definitely and clearly because of some images, Apple does not like. So this method of finding out which of those images is it complaining, seems to be the way to go.Porcelain
Does any one is able to solve this crash issue with different solutionAceous
For me this issue is solved with new xcode 8.1 beta without changing anything in the code or image assetsAceous
Even i have same issue where i don't have any P3 assets and all are sRGB. Still i have this random crash in every run. Unfortunately i could n't try xcode 8.1 beta due to some authentic issues in my organisation. If any one has any other solution please help me with your approach.Sierrasiesser
L
32

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 "------------------------------"
Louisalouisburg answered 19/9, 2016 at 10:29 Comment(7)
Our assets don't contain any faulty images, yet we're still getting these errors.Metope
@animaonline, It helps if app really contains 16-bit or P3 assets.Louisalouisburg
I think the main problem is that no one has actually confirmed that this error is caused by assets.Metope
worked at first, but then not, it just does not crash at the same placeDelius
The script didn't work for me, but using ImageOptim didRolfston
Work for me, amazing. My crash logs did not concern anything about this, just try for lucky.Hegarty
if any file path includes whitespace, your solution will fail for the fileCombat
B
16

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

Boss answered 19/9, 2016 at 21:13 Comment(2)
I am not able to download the sample project. Can you share the project to reproduce the crashDerosier
Thanks. Issues related to Asset Catalog, just change color space from Adobe RGB (1998) to sRGB.Makassar
P
13

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 "------------------------------"
Pete answered 13/10, 2016 at 11:34 Comment(3)
This script is little bit more accurate. Спасибо, Никита.Unsay
This works like a charm. Simple but effective script. For people who don't know how to run this script.. Steps: 1) Put this script in txt file and rename it to AssetsScript.sh 2) Goto Images.xcassets enclosing folder and keep the script file 3) In command line go to the folder where your script file exists 4) Change script files permissions to executable (chmod 755 AssetsScript.sh) 5) execute script file with directoryName as parameter in command line itself (./AssetsScript.sh Images.xcassets). Boom this converts all your assets to required format and done. Application will now works fine.Sierrasiesser
In one line, while IFS= read -d '' -r file; do if [ $(file "$file" | grep -c '16-bit') -eq 1 ]; then sips -m '/System/Library/Colorsync/Profiles/sRGB Profile.icc' "$file"; fi done < <(find . -print0), which will just convert 16-bit image to 8-bitCombat
P
3

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

Priggery answered 9/9, 2016 at 14:41 Comment(2)
What do you mean? Could you elaborate?Metope
Showing an image with the Adobe RGB (1998) colorspace was working for me on debug on a device with Xcode 8 and Swift 3, but wasn't on release on iOS 9. Changing the colorspace made it work.Grizelda
T
1

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.

Trinidad answered 17/10, 2016 at 21:2 Comment(8)
Hi. Help! I'm experiencing something like this, except ONLY in AppStore. When I build my app directly on an iPhone with iOS 9.2.1 it doesn't crash, nor on simulator, but when I download the exact same version/build from AppStore it does crash. Was this the case with you as well?Selfimportant
@Selfimportant no, it was crashing in the debug build. Are you using core data or anything else that might have a problem when over-writing an old build? Just a thought.Trinidad
Good thought, and yeah, I am using core data in some parts of the app. But after a lot of testing I am quite sure that it has nothing to do with that. Core data has nothing do do with my images, and nearly all my stack-traces from my crash reporting system says that UIImage(imageNamed:) is the bad guy. Oh, and it happens on clean installs as well. Over 7000 crashes the last two days, only affecting iOS 9.0.2 through 9.2.1.. Not iOS 9.3 or later.. So weird. And does not happen when I build it now. Only AppStore. Impossible to debug. I sent a TSI-ticket to Apple just now.Selfimportant
Ooh. That is a gooey one. Just had another thought.. What version of Swift is the app store version using? I think I experienced this in Swift 2.2 or 2.3. Not Swift 3. I imagine you're building now with Swift 3 and can't reproduce it?Trinidad
No, but it is very interesting that you're saying that! We have had this app on App Store for a long time. The previous version on App Store was written in Swift 2.3 and did not experience this bug. This new version on App Store that I uploaded a few days ago (the one that crashes) has very few but very large changes, including being converted to Swift 3. Another mentionable change is the addition of a widget exclusively for iOS 10.Selfimportant
Eek. I'm sorry I can't help further, but hope I was able to help to some degree, if nothing else for process of elimination. :) Good luck!Trinidad
Oh, and I have 8.0 as deployment target too, as you did in your answer, always have been. Yeah, its an ugly one ;P Yes, thanks for your help, very kind of you! :)Selfimportant
I also have crash in only iOS 9.2.x, ONLY in Appstore too. When i build my app directly or build to ipa file into iOS 9.2 device, no crash, can't reproduce crash case.Felid
R
0

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.

Roselba answered 27/9, 2016 at 16:25 Comment(0)
O
0

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
Omnirange answered 18/9, 2017 at 12:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.