Xcode crashing on startup possibly due to too many

2019-02-17 07:07发布

问题:

I just got a new Mac and downloaded Xcode so everything is fresh. On opening Xcode for the first time I accidentally told it to open my src/ folder instead of /src/myLatestProject so my hunch is Xcode went and tried to open every project in my src/ directory (hundreds). It beachballed for a few seconds and then crashed. The issue now is that Xcode seems to have remembered that I want that multitude of projects opened at app startup or it's trying to parse hundreds of git repos and I'm stuck in open/beachball/crash purgatory. How can I reset Xcode's prefs so it won't try to be so helpful and open every bit of source code on my computer?

EDIT: I've confirmed it's only crashing for my account. If I create a test user and open Xcode, everything is fine.

 Application Specific Information:
ProductBuildVersion: 5A3005
ASSERTION FAILURE in /SourceCache/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport-3575/Xcode3Sources/XcodeIDE/Frameworks/DevToolsBase/pbxcore/Xcode3Model/Xcode3OCUnitTestableDataSource.m:191
Details:  ([_indexableIdsToTestableTokens objectForKey:indexableIdentifier]) should be nil, but it is <Xcode3OCUnitTestableDataSourceToken: 0x7fe73b531ae0>
Object:   <Xcode3OCUnitTestableDataSource: 0x7fe7359c79f0>
Method:   -setTestableToken:indexableIdentifier:
Thread:   <NSThread: 0x7fe732415570>{name = (null), num = 1}
Hints:   None
Backtrace:
  0  0x0000000109575ea8 -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
  1  0x00000001082fc7a5 _DVTAssertionHandler (in DVTFoundation)
  2  0x00000001082fcad4 _DVTAssertionFailureHandler (in DVTFoundation)
  3  0x000000010e8ef3ca -[Xcode3OCUnitTestableDataSource setTestableToken:indexableIdentifier:] (in DevToolsCore)
  4  0x000000010e8f2261 -[Xcode3OCUnitTestableDataSourceToken _initWithDataSource:indexableIdentifier:callbackBlock:] (in DevToolsCore)
  5  0x000000010e8ef87d +[Xcode3OCUnitTestableDataSource testableDataSourceTokenForWorkspace:indexableIdentifier:callbackBlock:] (in DevToolsCore)
  6  0x000000010ea0a464 -[Xcode3OCUnitTestable initWithTarget:] (in DevToolsCore)
  7  0x000000010e9d7b69 -[Xcode3Project _updateTestablesForTargetProxies:] (in DevToolsCore)
  8  0x000000010e9d074d -[Xcode3Project syncTargetProxiesWithProjectTargets] (in DevToolsCore)
  9  0x000000010830e618 -[NSObject(DVTObservingConvenience) _dvt_newObserverForKeyPath:options:owner:withHandlerBlock:] (in DVTFoundation)
 10  0x000000010828e5d3 -[NSObject(DVTObservingConvenience) dvt_newObserverForKeyPath:options:withHandlerBlock:] (in DVTFoundation)
 11  0x000000010e9d1815 -[Xcode3Project initWithFilePath:extension:workspace:error:] (in DevToolsCore)
 12  0x0000000108d899ef __73+[IDEContainer retainedContainerAtFilePath:fileDataType:workspace:error:]_block_invoke_2 (in IDEFoundation)
 13  0x00007fff91d9d2ad _dispatch_client_callout (in libdispatch.dylib)
 14  0x00007fff91d9e166 _dispatch_barrier_sync_f_invoke (in libdispatch.dylib)
 15  0x000000010833a0ec DVTSyncPerformBlock (in DVTFoundation)
 16  0x000000010825dfe3 -[DVTDispatchLock performLockedBlock:] (in DVTFoundation)
 17  0x0000000108d893f5 __73+[IDEContainer retainedContainerAtFilePath:fileDataType:workspace:error:]_block_invoke (in IDEFoundation)
 18  0x000000010830f2ed -[DVTModelObjectGraph performBlockCoalescingModelChanges:] (in DVTFoundation)
 19  0x0000000108cc9579 +[IDEContainer retainedContainerAtFilePath:fileDataType:workspace:error:] (in IDEFoundation)
 20  0x0000000108d9eb40 -[IDEFileReference _recalculateReferencedContainer] (in IDEFoundation)
 21  0x0000000108cdcf48 -[IDEFileReference referencedContainer] (in IDEFoundation)
 22  0x0000000108ce4200 -[IDEContainerQuery _traverseContainerGraphObject:forDeletion:checkedContainers:insertedMatches:deletedMatches:] (in IDEFoundation)
 23  0x0000000108ce617b -[IDEContainerQuery _traverseContainerGraphObjects:forDeletion:insertedMatches:deletedMatches:] (in IDEFoundation)
 24  0x0000000108ce5ec4 -[IDEContainerQuery _objectsDidChange:] (in IDEFoundation)
 25  0x00007fff8d6eefcc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ (in CoreFoundation)
 26  0x00007fff8d5e2c5d _CFXNotificationPost (in CoreFoundation)
 27  0x00007fff8a3c14aa -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation)
 28  0x00000001082a7085 -[DVTModelObjectGraph _coalescingTick] (in DVTFoundation)
 29  0x0000000108cd1912 -[IDEGroup _setSubitems:] (in IDEFoundation)
 30  0x0000000108cdee30 -[IDEFolder _updateSubitemsWithFileNames:] (in IDEFoundation)
 31  0x0000000108d8eedb __32-[IDEFolder _filePathDidChange:]_block_invoke94 (in IDEFoundation)
 32  0x0000000108339fdc __DVTAsyncPerformBlock_block_invoke (in DVTFoundation)
 33  0x00007fff8d6517cc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ (in CoreFoundation)
 34  0x00007fff8d642ee5 __CFRunLoopDoBlocks (in CoreFoundation)
 35  0x00007fff8d64282b __CFRunLoopRun (in CoreFoundation)
 36  0x00007fff8d642275 CFRunLoopRunSpecific (in CoreFoundation)
 37  0x00007fff8b8aef0d RunCurrentEventLoopInMode (in HIToolbox)
 38  0x00007fff8b8aecb7 ReceiveNextEventCommon (in HIToolbox)
 39  0x00007fff8b8aeabc _BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox)
 40  0x00007fff8ad0e28e _DPSNextEvent (in AppKit)
 41  0x00007fff8ad0d8db -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit)
 42  0x00007fff8ad019cc -[NSApplication run] (in AppKit)
 43  0x00007fff8acec803 NSApplicationMain (in AppKit)
 44  0x00007fff89ff25fd start (in libdyld.dylib)

回答1:

Not sure which one fixed it but I ran the following in terminal and now it works again:

cd ~/Library
sudo rm -rf './Preferences/com.apple.dt.Xcode.plist' './Autosave Information/com.apple.dt.Xcode.plist'  './Autosave Information/Unsaved Xcode Document.xcworkspace' './Caches/com.apple.dt.Xcode'

WARNING: Note this may delete other preferences such as key bindings so beware if you have a lot of customization of your xcode environment.



回答2:

Open finder and go to following path and delete the folders made their, these are the folders made whenever we open any project in xcode temporarily:

/Users/MyMac/Library/Developer/Xcode/DerivedData/


回答3:

On my Xcode6/Yosemite mac there is no "Autosave Information" folder, so I deleted ~/Library/Saved Application State/com.apple.dt.Xcode.savedState folder instead and it stopped crashing.



回答4:

If you have any open swift file in a new window (for example when you double click on a .swift file in xCode and it opens in a new window) when xCode opens this might be an issue. I think I had this window opened when closing xCode, then when opening xCode this window opens up again and for some reason crashes xCode. Try to close this open window quickly before it crashes. Strange, but that worked for me.



回答5:

The scenario to make Xcode crashing was a bit different on my side. Indeed I had the same callstack error:

Application Specific Information:
ProductBuildVersion: 5A3005
ASSERTION FAILURE in /SourceCache/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport-3575/Xcode3Sources/XcodeIDE/Frameworks/DevToolsBase/pbxcore/Xcode3Model/Xcode3OCUnitTestableDataSource.m:191
Details:  ([_indexableIdsToTestableTokens objectForKey:indexableIdentifier]) should be nil, but it is <Xcode3OCUnitTestableDataSourceToken: 0x7fe73b531ae0>
Object:   <Xcode3OCUnitTestableDataSource: 0x7fe7359c79f0>
Method:   -setTestableToken:indexableIdentifier:
Thread:   <NSThread: 0x7fe732415570>{name = (null), num = 1}
Hints:   None

But I had to duplicate an existing project (.xcodeproj file) in order to have in my workspace an app depending on other projects (Target Dependencies in Build Phases) in my workspace (used as a debug app) and an app not depending on anything only linking to the resulting build output of the corresponding projects target (in my case frameworks inside Link Binary With Libraries in Build Phases). The issue was that each time I imported the duplicated project to my workspace it crashed Xcode... As the crash stack trace was talking about test things I just went through the project.pbxproj and removed all occurrences of test string in that file (well I tool care about section to avoid corrupting my file).

Something was going wrong with the duplicated xctest target inside the prject. Once I tried again to import it again in my workspace it worked fine.

Hope it can help



回答6:

I have removed entirely the folder Library/Developer : Close XCode

rm -r /Library/Developer

And say yes for every files



回答7:

No solution worked for me in case you have workspace . But i found out one ..

  • delete workspace file if you have one . install pod again using "pod install" in terminal (need to move to your project folder).

  • open workspace again .. and it will solve this issue