简体   繁体   中英

JSONDecoder crashing on TestFlight / AppStore

I am working on my Apple Watch app. Most of my components use JSON and use the Swift Codable protocol to decode JSON. Now I wanted to prepare my release, but I received a message by a Beta tester that the App was always crashing on his Series 3.

After I installed the TestFlight build on my Series 3 I could reproduce the issue. The crash logs from TestFlight and the crash logs extracted from my iPhone indicate that the crash is happening while the JSON gets decoded.

I have rather complex JSON structures, but I did not do any changes to them since the last update. Furthermore, decoding JSON works fine on Xcode builds (also on Series 3) and on newer Apple Watches (Series 4 + 5). I am struggling to find out what could cause the issue. I discovered a post in the Apple developer forums with a similar issue, but without a solution to it: https://forums.developer.apple.com/thread/124627

Here's a part of the Stacktrace of my crash log:

Date/Time:           2020-02-05 08:37:42.9924 +0100
Launch Time:         2020-02-05 08:37:40.0000 +0100
OS Version:          Watch OS 6.1.2 (17S5792a)
Release Type:        User
Baseband Version:    4.40.02
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Application Specific Information:
abort() called

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x4d9aefc8 __pthread_kill + 8
1   libsystem_pthread.dylib         0x4da260be pthread_kill + 108
2   libsystem_c.dylib               0x4d9383a4 abort + 84
3   libswiftCore.dylib              0x6cffbade swift_vasprintf+ 2341598 (char**, char const*, char*) + 0
4   libswiftCore.dylib              0x6d00932c swift::TargetMetadata<swift::InProcess>::getGenericArgs+ 2396972 () const + 0
5   libswiftCore.dylib              0x6d00508c _swift_initClassMetadataImpl+ 2379916 (swift::TargetClassMetadata<swift::InProcess>*, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const* const*, unsigned long*, bool) + 28
6   libswiftCore.dylib              0x6d005c86 swift_initClassMetadata2 + 22
7   libswiftCore.dylib              0x6cfdc6fc type metadata completion function for _KeyedDecodingContainerBox + 50
8   libswiftCore.dylib              0x6d00a6c2 swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const*>::doInitialization+ 2401986 (swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) + 178
9   libswiftCore.dylib              0x6d003a0c swift_getGenericMetadata + 1124
10  libswiftCore.dylib              0x6cdf4210 KeyedDecodingContainer.init<A>+ 213520 (_:) + 40
11  libswiftFoundation.dylib        0x6d156e0a __JSONDecoder.container<A>+ 323082 (keyedBy:) + 678
12  libswiftFoundation.dylib        0x6d1a3a1c protocol witness for Decoder.container<A>+ 637468 (keyedBy:) in conformance __JSONDecoder + 18
13  libswiftFoundation.dylib        0x6d1592b6 protocol witness for Decoder.container<A>+ 332470 (keyedBy:) in conformance __JSONDecoder + 32
14  libswiftCore.dylib              0x6cfdb1cc dispatch thunk of Decoder.container<A>+ 2208204 (keyedBy:) + 24
15  WatchSonos WatchKit Extension   0x00440bf2 0x358000 + 953330
16  WatchSonos WatchKit Extension   0x0043d08c 0x358000 + 938124
17  libswiftCore.dylib              0x6cfdb156 dispatch thunk of Decodable.init+ 2208086 (from:) + 12
18  libswiftFoundation.dylib        0x6d16fbee __JSONDecoder.unbox_+ 424942 (_:as:) + 4014
19  libswiftFoundation.dylib        0x6d156816 JSONDecoder.decode<A>+ 321558 (_:from:) + 642
20  libswiftFoundation.dylib        0x6d22af98 dispatch thunk of JSONDecoder.decode<A>+ 1191832 (_:from:) + 28
21  WatchSonos WatchKit Extension   0x0045db0c 0x358000 + 1071884
22  WatchSonos WatchKit Extension   0x00461cce 0x358000 + 1088718
23  WatchSonos WatchKit Extension   0x00461bde 0x358000 + 1088478
24  WatchSonos WatchKit Extension   0x00420ffa 0x358000 + 823290
25  WatchSonos WatchKit Extension   0x00425914 0x358000 + 842004
26  libdispatch.dylib               0x4d851846 _dispatch_call_block_and_release + 10
27  libdispatch.dylib               0x4d8528b8 _dispatch_client_callout + 6
28  libdispatch.dylib               0x4d85c6b0 _dispatch_main_queue_callback_4CF + 868
29  CoreFoundation                  0x4dcdbbaa __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 10
30  CoreFoundation                  0x4dcd7c00 __CFRunLoopRun + 1832
31  CoreFoundation                  0x4dcd723a CFRunLoopRunSpecific + 370
32  GraphicsServices                0x50aebcd0 GSEventRunModal + 96
33  UIKitCore                       0x65c91580 UIApplicationMain + 1730
34  libxpc.dylib                    0x4da73c80 _xpc_objc_main.cold.3 + 152
35  libxpc.dylib                    0x4da649b0 _xpc_objc_main + 184
36  libxpc.dylib                    0x4da668c4 xpc_main + 110
37  Foundation                      0x4e56b0c6 +[NSXPCListener serviceListener] + 0
38  PlugInKit                       0x556d726c 0x556c5000 + 74348
39  WatchKit                        0x5cfe9afe WKExtensionMain + 62
40  WatchKit                        0x5d09f020 main + 10

Here's the position in the code that crashes:

    required public init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        self.id = try values.decode(String.self, forKey: .id)

        do {

            if values.contains(.groups) {
                let groups = try values.decode(Dictionary<String, SonosGroup>.self, forKey: .groups)
                self.groups = groups
            }


            if values.contains(.players) {
                let players = try values.decode(Array<SonosPlayer>.self, forKey: .players)
                self.players = players
            }

        }catch let error {
            print("Error decoding groups \(error)")
        }

    }

For me this looks like an Apple bug and I filed feedback for it, but this is no solution for the next release.

Does anyone know what's the difference between a TestFlight build and an Xcode release build? I tried setting a different optimization level, disabling bitcode (not allowed for Apple Watch Apps) and I started replacing Codable with the good old JSONSerialization .

If anyone knows more about it, thank you for that.

Kind regards Alex

I was having a very similar problem with Encodable and Decodable's in a swift package. Setting DEAD_CODE_STRIPPING = NO in my apps target fixed it. This seems to be a weird leftover of this bug: https://bugs.swift.org/browse/SR-11564?focusedCommentId=51285&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-51285

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM