MobileNativeFoundation / rules_xcodeproj

Bazel rules for generating Xcode projects.
MIT License
526 stars 86 forks source link

Bug: Crash when running an iOS app with a framework named "CoreUI" #2846

Closed jpsim closed 10 months ago

jpsim commented 10 months ago

Description

When running an iOS app with a framework named "CoreUI", the app will crash on launch with an uncaught exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CUICatalog initWithName:fromBundle:error:]: unrecognized selector sent to instance 0x600002610d80'

Presumably because CoreUI is also a private framework: https://github.com/nst/iOS-Runtime-Headers/blob/master/PrivateFrameworks/CoreUI.framework/CUICatalog.h

And presumably because rules_xcodeproj has different framework search path ordering than bazel on the CLI / Xcode.

Reproduction steps

With this project: coreui-crash.zip

  1. bazel run xcodeproj && xed Demo.xcodeproj
  2. cmd-R to build and run the CoreUI app

The app should crash on launch with the following uncaught exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CUICatalog initWithName:fromBundle:error:]: unrecognized selector sent to instance 0x600002610d80'
*** First throw call stack:
(
  0   CoreFoundation                      0x0000000180491128 __exceptionPreprocess + 172
  1   libobjc.A.dylib                     0x000000018008412c objc_exception_throw + 56
  2   CoreFoundation                      0x00000001804a5f78 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
  3   CoreFoundation                      0x0000000180495278 ___forwarding___ + 1280
  4   CoreFoundation                      0x000000018049759c _CF_forwarding_prep_0 + 92
  5   UIKitCore                           0x00000001856b8134 -[_UIAssetManager _initWithName:inBundle:idiom:lock:allowMissingCatalog:] + 340
  6   UIKitCore                           0x00000001856b9028 ____UIKitSharedBoundingPathDataManager_block_invoke + 104
  7   libdispatch.dylib                   0x00000001031c993c _dispatch_client_callout + 16
  8   libdispatch.dylib                   0x00000001031cb3dc _dispatch_once_callout + 84
  9   UIKitCore                           0x00000001856b8fbc __UIKitSharedBoundingPathDataManager + 60
  10  UIKitCore                           0x0000000184ece104 -[_UIScreenComplexBoundingPathUtilities _loadBitmapForScreen:type:] + 256
  11  UIKitCore                           0x0000000184ecd414 -[_UIScreenComplexBoundingPathUtilities initWithScreen:] + 128
  12  UIKitCore                           0x0000000184ed6558 +[_UIScreenBoundingPathUtilities boundingPathUtilitiesForScreen:] + 80
  13  UIKitCore                           0x0000000184ee0070 -[UIScreen _boundingPathUtilities] + 40
  14  UIKitCore                           0x0000000185334228 -[UIWindow _boundingPath] + 140
  15  UIKitCore                           0x000000018580b088 -[UIView(UIViewBoundingPathSupportInternal) _effectiveBoundingPathAndBoundingPathView:] + 168
  16  UIKitCore                           0x000000018580a8fc -[UIView(UIViewBoundingPathSupport) _rectTuckedAgainstBoundingPathEdge:withSize:cornerRadii:minimumPadding:] + 228
  17  UIKitCore                           0x0000000184aeb428 -[_UISheetLayoutInfo _unsafeInsets] + 116
  18  UIKitCore                           0x0000000184aeb5f8 -[_UISheetLayoutInfo _marginsWhenFloating] + 132
  19  UIKitCore                           0x0000000184aebefc -[_UISheetLayoutInfo _isEdgeAttached] + 40
  20  UIKitCore                           0x0000000184aecc44 -[_UISheetLayoutInfo _effectiveAppearance] + 52
  21  UIKitCore                           0x0000000184aed484 -[_UISheetLayoutInfo _activeDetents] + 224
  22  UIKitCore                           0x0000000184aeccf8 -[_UISheetLayoutInfo _offsetForCurrentActiveDetent] + 36
  23  UIKitCore                           0x0000000184aee7dc -[_UISheetLayoutInfo _frameOfPresentedViewInContainerView] + 76
  24  UIKitCore                           0x0000000184aee900 -[_UISheetLayoutInfo _hostedFrameOfPresentedViewInContainerView] + 44
  25  UIKitCore                           0x0000000185586a24 -[UISheetPresentationController _containerViewLayoutSubviews] + 584
  26  UIKit                               0x00000001be696238 -[UISheetPresentationControllerAccessibility _containerViewLayoutSubviews] + 56
  27  UIKitCore                           0x00000001857ced84 -[UITransitionView layoutSubviews] + 68
  28  UIKitCore                           0x0000000185806d78 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1492
  29  QuartzCore                          0x0000000189ffa5b0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 440
  30  UIKitCore                           0x00000001857f6260 -[UIView(Hierarchy) layoutBelowIfNeeded] + 292
  31  UIKitCore                           0x0000000185584f54 -[UISheetPresentationController presentationTransitionWillBegin] + 1132
  32  UIKitCore                           0x0000000184ae1b94 __80-[UIPresentationController _initViewHierarchyForPresentationSuperview:inWindow:]_block_invoke + 1896
  33  UIKitCore                           0x0000000184adfe48 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_3 + 292
  34  UIKitCore                           0x0000000184ae4e64 +[UIPresentationController _scheduleTransition:] + 72
  35  UIKitCore                           0x0000000184adfa7c -[UIPresentationController runTransitionForCurrentState] + 1468
  36  UIKitCore                           0x0000000184add6b8 -[UIPresentationController _presentWithAnimationController:inWindow:interactionController:target:didFinish:] + 564
  37  UIKitCore                           0x0000000185325d64 -[UIWindow addRootViewControllerViewIfPossible] + 328
  38  UIKitCore                           0x000000018532569c -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 212
  39  UIKitCore                           0x0000000185326504 -[UIWindow _setHidden:forced:] + 228
  40  UIKit                               0x00000001be7c6290 -[UIWindowAccessibility _orderFrontWithoutMakingKey] + 144
  41  UIKitCore                           0x0000000185335374 -[UIWindow _mainQueue_makeKeyAndVisible] + 36
  42  UIKit                               0x00000001be7c72ac -[UIWindowAccessibility makeKeyAndVisible] + 56
  43  SwiftUI                             0x00000001c49a9e30 OUTLINED_FUNCTION_7 + 13864
  44  SwiftUI                             0x00000001c49aaa88 OUTLINED_FUNCTION_7 + 17024
  45  UIKitCore                           0x0000000184805e18 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1012
  46  UIKitCore                           0x00000001852f1644 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 804
  47  UIKitCore                           0x00000001852f192c -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 356
  48  UIKitCore                           0x0000000184de0cc4 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 260
  49  FrontBoardServices                  0x0000000186e03190 -[FBSScene _callOutQueue_didCreateWithTransitionContext:completion:] + 296
  50  FrontBoardServices                  0x0000000186e2c3d4 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.82 + 224
  51  FrontBoardServices                  0x0000000186e0fd6c -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
  52  FrontBoardServices                  0x0000000186e2c14c __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 284
  53  libdispatch.dylib                   0x00000001031c993c _dispatch_client_callout + 16
  54  libdispatch.dylib                   0x00000001031cd534 _dispatch_block_invoke_direct + 392
  55  FrontBoardServices                  0x0000000186e4fb24 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
  56  FrontBoardServices                  0x0000000186e4fa00 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 196
  57  FrontBoardServices                  0x0000000186e4fb58 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 24
  58  CoreFoundation                      0x00000001803f1f18 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
  59  CoreFoundation                      0x00000001803f1e60 __CFRunLoopDoSource0 + 172
  60  CoreFoundation                      0x00000001803f1628 __CFRunLoopDoSources0 + 320
  61  CoreFoundation                      0x00000001803ebcb8 __CFRunLoopRun + 768
  62  CoreFoundation                      0x00000001803eb5a4 CFRunLoopRunSpecific + 572
  63  GraphicsServices                    0x000000018e9fbae4 GSEventRunModal + 160
  64  UIKitCore                           0x00000001852f02e4 -[UIApplication _run] + 868
  65  UIKitCore                           0x00000001852f3f5c UIApplicationMain + 124
  66  SwiftUI                             0x00000001c51fc1b0 OUTLINED_FUNCTION_70 + 500
  67  SwiftUI                             0x00000001c51fc050 OUTLINED_FUNCTION_70 + 148
  68  SwiftUI                             0x00000001c4f02fa4 OUTLINED_FUNCTION_2 + 92
  69  CoreUI                              0x000000010310bb
libc++abi: terminating due to uncaught exception of type NSException

Building and running works from the command line: bazel run //:CoreUIApp

Building and running works from Xcode and the command line if name in the BUILD file is renamed to something else, like CoolUI.

Expected behavior

The app should run and not crash just as it does with bazel run //:CoreUIApp on the command line.

rules_xcodeproj version

1.14.2

Xcode version

15.1

Bazel version

7.0.0

rules_apple version

3.1.1

rules_swift version

1.13.0

Additional information

No response

brentleyjones commented 10 months ago

This is an issue with how Xcode launches applications. I believe it's because it sets a custom DYLD_LIBRARY_PATH that interferes with this. If you launch the application on the simulator by tapping the icon after the crash, it works just fine. I encountered this issue many years ago (pre-Bazel), and in general you can name your frameworks after public or private system frameworks if you want to launch an application with Xcode.

jpsim commented 10 months ago

I see, thanks for the info.