Libc++abi.dylib: Terminating With Uncaught Exception of Type NSException and OS_ACTIVITY_MODE
How to fix libc++abi.dylib: terminating with uncaught exception of type NSException?
Recently when developing my app, a strange error appear without any other clue.
libc++abi.dylib: terminating with uncaught exception of type NSException
It happens right after my app start, after app didFinishLaunchingWithOptions:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
I tried to set breakpoint and debug my app to track down the error statement but unsuccessful. None of my initial function throws any exception. Event the flash screen got load properly but the whole app crash right after.
This frustrated me so much because the only thing I saw from Log Output was the libc++abi.dylib error. I have no clue.
After searching a while on Google, I have found something. There a flag in App Running Scheme, Environment Variables that I set earlier that cut off the crash log. And it was OS_ACTIVITY_MODE is set to disable.
Remove this flag, or simply untick it, XCode now shows my whole running log.
It turns out after updating to new GoogleMobileAdsSDK, I forgot to set GADApplicationIdentifier int Info.plist.
APP[63286:2475094] *** Terminating app due to uncaught exception 'GADInvalidInitializationException', reason: 'The Google Mobile Ads SDK was initialized incorrectly. Google AdMob publishers should follow instructions here: https://googlemobileadssdk.page.link/admob-ios-update-plist to include the AppMeasurement framework, set the -ObjC linker flag, and set GADApplicationIdentifier with a valid App ID. Google Ad Manager publishers should follow instructions here: https://googlemobileadssdk.page.link/ad-manager-ios-update-plist'
*** First throw call stack:
(
0 CoreFoundation 0x00000001084c26fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000107a66ac5 objc_exception_throw + 48
2 CoreFoundation 0x00000001084c2269 -[NSException raise] + 9
3 APP 0x0000000101082418 GADVerifyApplicationID + 148
4 APP 0x0000000101082fd9 GADVerifyApplicationID + 3157
5 libdispatch.dylib 0x00000001097ead7f _dispatch_call_block_and_release + 12
6 libdispatch.dylib 0x00000001097ebdb5 _dispatch_client_callout + 8
7 libdispatch.dylib 0x00000001097f9080 _dispatch_main_queue_callback_4CF + 1540
8 CoreFoundation 0x00000001084298a9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
9 CoreFoundation 0x0000000108423f56 __CFRunLoopRun + 2310
10 CoreFoundation 0x0000000108423302 CFRunLoopRunSpecific + 626
11 GraphicsServices 0x000000010ae7b2fe GSEventRunModal + 65
12 UIKitCore 0x000000011096eba2 UIApplicationMain + 140
13 APP 0x0000000100d8f73b main + 75
14 libdyld.dylib 0x0000000109860541 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Simply update my Info.plist file then the error is fixed.
The libc++abi.dylib crash could happen due to many other reasons, searching through Google you could see this error happens so much. One clue to solve this, as in my case, check if your Environment Variable OS_ACTIVITY_MODE is set then remove it.
Happy coding!