Mapbox-gl-native: Interface Builder designable fails to compile using CocoaPods

Created on 26 Sep 2017  Â·  22Comments  Â·  Source: mapbox/mapbox-gl-native

Platform: iOS
Mapbox SDK version: 3.6.4

Steps to trigger behavior

  1. Create a new Xcode project
  2. Include the Mapbox iOS SDK via CocoaPods
  3. Attempt to build application and view the resulting storyboard error:

screenshot 2017-09-26 13 09 40

Failed to render and update auto layout status for ViewController (BYZ-38-t0r):
The agent crashed Main.storyboard

Expected behavior

The application should compile without the IB Designables error.

Actual behavior

An IB Designables error is returned.

cc @1ec5 @friedbunny

build iOS upstream

Most helpful comment

This is a known issue in Xcode 9 (and 8?). The designable resources are stripped out of compiled frameworks. A workaround in the meantime would be to subclass MGLMapView and use that to render the designable.

All 22 comments

Though annoying and disconcerting, this error is cosmetic — the designable failing to load does not affect the storyboard or the app’s eventual layout.

I think we should consider removing our designable:

  • It delays Interface Builder loading any storyboard that includes our map view, because it must reach into our SDK to render/present the designable.
  • It often fails to render at all.
  • It just doesn’t do very much — our designable tells the user that they must sign up for a token, but doesn’t recognize when a token is set or allow the user to click on the faux-link we show.
  • Does it update the position of its subviews? 🤔

screen shot 2017-09-26 at 1 23 35 pm

Does it update the position of its subviews?

Yeah, kinda:

screen shot 2017-09-26 at 1 31 34 pm

This is a known issue in Xcode 9 (and 8?). The designable resources are stripped out of compiled frameworks. A workaround in the meantime would be to subclass MGLMapView and use that to render the designable.

The workaround proposed by @frederoni worked for me.

@frederoni that worked for me also. Thank you very much!

As reports continue to come in from users hitting this issue, I’d again put forward that we should partially revert #1184.

I wouldn't like to create a subclass of MGLMapView in my project as a "workaround". I prefer a workaround to not alter the project's structure. I'll wait until there's some kind of solution to this. Is this then a Xcode issue, not Mapbox? Is there a radar filled in?

All that's needed is for Mapbox to add an override for init(coder aDecoder: NSCoder) to the MGLMapView class.

override init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

This is the cause for the IBDesignables agent crashing, because it overrides init(frame) without also overriding init(coder).
Source: https://stackoverflow.com/questions/31265906/ibdesignable-crashing-agent

The workaround until then is to add the MGLMapView to your ViewController programmatically instead of in Storyboard.

Once I remove the MGLMapView from my storyboard and add it programmatically, the error goes away.

All that's needed is for Mapbox to add an override for init(coder aDecoder: NSCoder) to the MGLMapView class.

The iOS and macOS implementations of MGLMapView already override -[MGLMapView initWithCoder:]:

https://github.com/mapbox/mapbox-gl-native/blob/43c6f6b3b0ead73d0c94aa7646e3d47568b924d8/platform/ios/src/MGLMapView.mm#L307-L315

https://github.com/mapbox/mapbox-gl-native/blob/43c6f6b3b0ead73d0c94aa7646e3d47568b924d8/platform/macos/src/MGLMapView.mm#L234-L239

This issue still exists with Xcode 9.2b2 and v3.7.0.

screen shot 2017-11-29 at 5 59 33 pm

file:///mapbox-gl-native/platform/ios/app/Main.storyboard: error: IB Designables: Failed to render and update auto layout status for MBXEmbeddedMapViewController (Tsi-Cv-L66): dlopen(test.xctest, 1): Library not loaded: @rpath/XCTest.framework/XCTest
Referenced from: test.xctest
Reason: image not found

Can confirm that it still happens on XCode 9.2 (9C40b) on v3.7.1

screen shot 2018-01-03 at 11 06 58 am


Additional crash log details

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (Code Signature Invalid)
Exception Codes:       0x0000000000000032, 0x00000001125e7000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace CODESIGNING, Code 0x2

kernel messages:

VM Regions Near 0x1125e7000:
    mapped file            00000001125b1000-00000001125e7000 [  216K] r--/rwx SM=COW  Object_id=d6a2d075
--> mapped file            00000001125e7000-00000001125e9000 [    8K] r-x/r-x SM=PRV  Object_id=cd7b2b75
    Dispatch continuations 0000000112600000-0000000113600000 [ 16.0M] rw-/rwx SM=PRV  

Application Specific Information:
dyld: in dlopen()
/someApp/Pods/Mapbox-iOS-SDK/dynamic/Mapbox.framework/Mapbox
CoreSimulator 494.33 - Device: IBSimDeviceTypeiPad2x - Runtime: iOS 11.2 (15C107) - DeviceType: IBSimDeviceTypeiPad2x

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   dyld_sim                        0x0000000100386249 memcmp + 11
1   dyld_sim                        0x00000001003754c5 ImageLoaderMachO::validateFirstPages(linkedit_data_command const*, int, unsigned char const*, unsigned long, long long, ImageLoader::LinkContext const&) + 73
2   dyld_sim                        0x00000001003782b6 ImageLoaderMachOCompressed::instantiateFromFile(char const*, int, unsigned char const*, unsigned long, unsigned long long, unsigned long long, stat const&, unsigned int, unsigned int, linkedit_data_command const*, encryption_info_command const*, ImageLoader::LinkContext const&) + 278
3   dyld_sim                        0x000000010037465f ImageLoaderMachO::instantiateFromFile(char const*, int, unsigned char const*, unsigned long, unsigned long long, unsigned long long, stat const&, ImageLoader::LinkContext const&) + 143
4   dyld_sim                        0x0000000100367473 dyld::loadPhase6(int, stat const&, char const*, dyld::LoadContext const&) + 599
5   dyld_sim                        0x000000010036bad3 dyld::loadPhase5(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 855
6   dyld_sim                        0x000000010036b758 dyld::loadPhase4(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 177
7   dyld_sim                        0x000000010036b502 dyld::loadPhase3(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 1441
8   dyld_sim                        0x000000010036ad27 dyld::loadPhase1(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 135
9   dyld_sim                        0x00000001003671f6 dyld::loadPhase0(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 194
10  dyld_sim                        0x0000000100366ec3 dyld::load(char const*, dyld::LoadContext const&, unsigned int&) + 178
11  dyld_sim                        0x000000010036dfc6 dlopen + 627
12  libdyld.dylib                   0x000000010a0e7a47 dlopen + 86
13  com.apple.dt.IBFoundation       0x00000001037f8268 -[IBAbstractInterfaceBuilderTool _resultByLoadingUnloadedBundleInstance:] + 154
14  com.apple.dt.IBFoundation       0x00000001037f890d -[IBAbstractInterfaceBuilderTool loadBuiltLiveViewBundleInstances:] + 809
15  com.apple.dt.IBFoundation       0x00000001037f2b55 __80-[IBMessageReceiveChannel deliverMessage:toTarget:withArguments:context:result:]_block_invoke + 94
16  com.apple.dt.IBFoundation       0x00000001037f2a1c -[IBMessageReceiveChannel deliverMessage:toTarget:withArguments:context:result:] + 496
17  com.apple.dt.IBFoundation       0x00000001037f238e __88-[IBMessageReceiveChannel runBlockingReceiveLoopNotifyingQueue:notifyingTarget:context:]_block_invoke + 143
18  libdispatch.dylib               0x000000010a4231ba _dispatch_client_callout + 8
19  libdispatch.dylib               0x000000010a42e8a7 _dispatch_sync_thread_bound_invoke + 108
20  libdispatch.dylib               0x000000010a4231ba _dispatch_client_callout + 8
21  libdispatch.dylib               0x000000010a42d3a4 _dispatch_main_queue_callback_4CF + 1260
22  com.apple.CoreFoundation        0x00000001053cee39 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
23  com.apple.CoreFoundation        0x0000000105393462 __CFRunLoopRun + 2402
24  com.apple.CoreFoundation        0x0000000105392889 CFRunLoopRunSpecific + 409
25  com.apple.Foundation            0x0000000103bd96de -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 274
26  com.apple.dt.IBFoundation       0x00000001037b460b -[IBAbstractPlatformTool startServingReceiveChannel:] + 469
27  com.apple.dt.IBFoundation       0x00000001037b48c6 -[IBAbstractPlatformTool startServingWriteDescriptor:readDescriptor:] + 119
28  com.apple.dt.IBFoundation       0x00000001037b53df +[IBAbstractPlatformTool main] + 1186
29  IBDesignablesAgentCocoaTouch    0x000000010035fba7 main + 34
30  libdyld.dylib                   0x000000010a0e6d81 start + 1

Can confirm that it still happens on Xcode 9.2 (9C40b) on v3.7.6

Same issue still exists with Xcode 9.3. Any update guys?

CocoaPods/CocoaPods#5334 is the root cause of this issue. https://github.com/mapbox/mapbox-gl-native/issues/10072#issuecomment-332273649 proposes working around the issue by removing the designable from the SDK. In the meantime, the following workarounds are currently available for developers to use today:

It’s worth keeping in mind that this is only an IB designable error – that is, it doesn’t affect whether your XIB or storyboard compiles when building your application for running or testing.

In our project we have two different ViewControllers with an MGLMapView. The layout renders as is should for the product on the device. It is however impossible to verify the design in the Interface Builder for ViewControllers which include the MGLMapView.

Nothing is presented in the IB according to the designs and constraints. "Failed to render and update auto layout status for ViewController - agent crashed..." This problem has existed for so long now, is there a solution upcoming or will we have to use the suggested workarounds?

Just want to chime in that subclassing MGLMapView works beautifully and took less than 30 seconds to implement.

Thanks, yes can also confirm that the subclassing works - thanks a lot!

Just subclass MGLMapView without any extra work? Doesn't seem to work for me.

@yehe01
Yes. This solved it for me:

import Mapbox
class x: MGLMapView{}

Assign the new class to the map's view. Restart Xcode.

This is still happening on Mapbox-iOS-SDK version 4.2.0 and Xcode 9.4.1. And I prefer not using the workaround because of additional subclass or another Swift file.

Closing this ticket in favor of https://github.com/mapbox/mapbox-gl-native/issues/13424. We can revisit in the future (and will be re-checking the behavior with new Xcode releases).

Was this page helpful?
0 / 5 - 0 ratings