Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestFlight installed app crash with Swift Package Manager dependencies

We have migrated some of our CocoaPod dependencies to be build and linked with Swift Package Manager in Xcode 11. However, whenever we submit application to AppStore Connect and distribute with TestFlight, the app crashes the moment it tries to use API from one of the SPM linked dependencies. Other builds (adhoc and development) are working fine. Some of the SPM dependencies are also linked 2 app extensions.

Did anyone encounter this issue, would you have any idea what is the problem and/or how to fix it?

Attaching stack trace for the crash. This one happens in ObjectMapper dependency.

Exception Type:  EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x00000000800000d0
Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
Terminating Process: exc handler [19562]
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   OurAwesomeApp                       0x0000000101693d14 nominal type descriptor for EnumTransform + 0
1   OurAwesomeApp                       0x000000010108cda0 <- infix<A>(_:_:) + 612 (__hidden#1488_:38)
2   OurAwesomeApp                       0x0000000101074434 <- infix<A>(_:_:) + 100 (__hidden#434_:36)
3   OurAwesomeApp                       0x0000000100cad360 TWSplitParticipant.mapping(map:) + 1388 (DataClasses.swift:1211)
4   OurAwesomeApp                       0x00000001010842cc Mapper.map(JSON:) + 1224 (__hidden#1191_:106)
5   OurAwesomeApp                       0x0000000101087c70 _hidden#1144_ + 24 (__hidden#110_:0)
6   libswiftCore.dylib              0x000000018f3cd61c $sSTsE10compactMapySayqd__Gqd__Sg7ElementQzKXEKlF + 732 (SequenceAlgorithms.swift:807)
7   OurAwesomeApp                       0x0000000101084a68 Mapper.mapArray(JSONArray:) + 212 (__hidden#1191_:166)
8   OurAwesomeApp                       0x0000000101082a8c Mapper.mapArray(JSONObject:) + 192 (__hidden#1191_:156)
9   OurAwesomeApp                       0x00000001010753d4 _hidden#461_ + 148 (__hidden#487_:92)
10  OurAwesomeApp                       0x0000000101088c8c _hidden#1301_ + 196
11  OurAwesomeApp                       0x0000000100cac720 TWSplitRequest.mapping(map:) + 812 (DataClasses.swift:1157)
12  OurAwesomeApp                       0x00000001010842cc Mapper.map(JSON:) + 1224 (__hidden#1191_:106)
13  OurAwesomeApp                       0x0000000101082988 Mapper.map(JSONObject:) + 160 (__hidden#1191_:89)
14  OurAwesomeApp                       0x00000001010752f0 _hidden#459_ + 644 (__hidden#487_:66)
15  OurAwesomeApp                       0x000000010108896c <- infix<A>(_:_:) + 152 (__hidden#1307_:116)
16  OurAwesomeApp                       0x0000000100ca7248 TWInvoice.mapping(map:) + 4000 (DataClasses.swift:377)
17  OurAwesomeApp                       0x00000001010842cc Mapper.map(JSON:) + 1224 (__hidden#1191_:106)
18  OurAwesomeApp                       0x0000000101087c70 _hidden#1144_ + 24 (__hidden#110_:0)
19  libswiftCore.dylib              0x000000018f3cd61c $sSTsE10compactMapySayqd__Gqd__Sg7ElementQzKXEKlF + 732 (SequenceAlgorithms.swift:807)
20  OurAwesomeApp                       0x0000000101084a68 Mapper.mapArray(JSONArray:) + 212 (__hidden#1191_:166)
21  OurAwesomeApp                       0x0000000101082a8c Mapper.mapArray(JSONObject:) + 192 (__hidden#1191_:156)
22  OurAwesomeApp                       0x00000001010753d4 _hidden#461_ + 148 (__hidden#487_:92)
23  OurAwesomeApp                       0x0000000101088c8c _hidden#1301_ + 196
24  OurAwesomeApp                       0x0000000100ca5b88 TWInvoicesByType.mapping(map:) + 328 (DataClasses.swift:266)
25  OurAwesomeApp                       0x00000001010842cc Mapper.map(JSON:) + 1224 (__hidden#1191_:106)
26  OurAwesomeApp                       0x0000000101082988 Mapper.map(JSONObject:) + 160 (__hidden#1191_:89)
27  OurAwesomeApp                       0x00000001010752f0 _hidden#459_ + 644 (__hidden#487_:66)
28  OurAwesomeApp                       0x000000010108896c <- infix<A>(_:_:) + 152 (__hidden#1307_:116)
29  OurAwesomeApp                       0x0000000100ca3adc TWAccount.mapping(map:) + 104 (DataClasses.swift:81)
30  OurAwesomeApp                       0x00000001010842cc Mapper.map(JSON:) + 1224 (__hidden#1191_:106)
31  OurAwesomeApp                       0x0000000101082988 Mapper.map(JSONObject:) + 160 (__hidden#1191_:89)
32  OurAwesomeApp                       0x0000000100c47c18 closure #1 in DataServer.getAccountInfo(_:) + 492 (DataServer.swift:949)
33  OurAwesomeApp                       0x00000001011d7888 _hidden#2846_ + 164
34  OurAwesomeApp                       0x00000001011db76c _hidden#2893_ + 52 (__hidden#578_:0)
35  OurAwesomeApp                       0x00000001011b55e0 _hidden#996_ + 28 (__hidden#578_:0)
36  libdispatch.dylib               0x0000000181e29610 _dispatch_call_block_and_release + 24 (init.c:1408)
37  libdispatch.dylib               0x0000000181e2a184 _dispatch_client_callout + 16 (object.m:495)
38  libdispatch.dylib               0x0000000181e0d35c _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 996 (inline_internal.h:2487)
39  CoreFoundation                  0x00000001820da3c4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1749)
40  CoreFoundation                  0x00000001820d53b8 __CFRunLoopRun + 2004 (CFRunLoop.c:3069)
41  CoreFoundation                  0x00000001820d48bc CFRunLoopRunSpecific + 464 (CFRunLoop.c:3192)
42  GraphicsServices                0x000000018bf40328 GSEventRunModal + 104 (GSEvent.c:2246)
43  UIKitCore                       0x000000018616a6d4 UIApplicationMain + 1936 (UIApplication.m:4753)
44  OurAwesomeApp                       0x0000000100c1048c main + 68 (OurAwesomeFactoryFactory.swift:25)
45  libdyld.dylib                   0x0000000181f5f460 start + 4
like image 462
Zdeněk Topič Avatar asked Nov 11 '19 12:11

Zdeněk Topič


People also ask

How does the Swift Package Manager know what Swift files to match?

By default, the Swift Package Manager will match the names of the targets defined within our manifest file with corresponding folders on disk in order to determine what Swift files that belong to each target.

How do I import a swift package into an app project?

Starting with Xcode 11, Swift packages can now be directly added and imported into an app project using Xcode’s new Swift Packages option, which is located within the File menu.

What is the Swift Package Manager in Xcode 11?

But now, starting with Xcode 11, the Swift Package Manager is finally becoming a true first class citizen within Apple’s suite of developer tools — so this week, let’s take a look at how it can be used to manage a project’s various dependencies — both internal and external ones.

Are swift packages cross-platform?

While all Swift packages are assumed to be cross-platform (and version agnostic) by default, by adding the platform parameter when initializing our Package within our manifest file, we can constrain our code to only support a given set of platforms and OS versions — like this, if we wanted to build a package that contains iOS 13-specific code:


Video Answer


1 Answers

2019-11-27 update

In the related Swift bug post, somebody has found a workaround:

Setting DEAD_CODE_STRIPPING = NO in our app’s target fixes the crash.


original post

First of all, it is a compiling issue of SPM. Simply just rollback to CocoaPods.

Until Xcode 11.2.1, Apple has not yet fixed this issue.

Delete all the derived files, clean the project. And then try running your project with the release configuration. Now you should be able to reproduce the crash.


I was using two libs named Moya and Parchment in an iOS project, with Swift Package Manager, migrated from CocoaPods. And the app downloaded from TestFlight crashes when the logic referencing the two libs is executed.

And the crash log looks completely like nonsense, pointing to a memory alignment issue of the method descriptor of a method.

Apple mentioned a known issue in Xcode release note, I don't know if it is related:

If an iOS, tvOS, or watchOS app uses a Swift Package that builds a dynamic library, it cannot be submitted to the App Store. (55564324)

Workaround: Modify the Package manifest to build a static library.

like image 108
iMoeNya Avatar answered Oct 22 '22 03:10

iMoeNya