简体   繁体   English

JSONDecoder 在 TestFlight / AppStore 上崩溃

[英]JSONDecoder crashing on TestFlight / AppStore

I am working on my Apple Watch app.我正在开发我的 Apple Watch 应用。 Most of my components use JSON and use the Swift Codable protocol to decode JSON.我的大部分组件都使用 JSON 并使用 Swift Codable 协议来解码 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.现在我想准备我的版本,但我收到了一个 Beta 测试人员的消息,说该应用程序总是在他的系列 3 上崩溃。

After I installed the TestFlight build on my Series 3 I could reproduce the issue.在我的系列 3 上安装 TestFlight 版本后,我可以重现该问题。 The crash logs from TestFlight and the crash logs extracted from my iPhone indicate that the crash is happening while the JSON gets decoded.来自 TestFlight 的崩溃日志和从我的 iPhone 中提取的崩溃日志表明,当 JSON 被解码时,崩溃正在发生。

I have rather complex JSON structures, but I did not do any changes to them since the last update.我有相当复杂的 JSON 结构,但自上次更新以来我没有对它们进行任何更改。 Furthermore, decoding JSON works fine on Xcode builds (also on Series 3) and on newer Apple Watches (Series 4 + 5).此外,解码 JSON 在 Xcode 版本(也在 Series 3 上)和较新的 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我在 Apple 开发者论坛上发现了一篇有类似问题的帖子,但没有解决方法: https : //forums.developer.apple.com/thread/124627

Here's a part of the Stacktrace of my crash log:这是我的崩溃日志 Stacktrace 的一部分:

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.对我来说,这看起来像是 Apple 的错误,我为此提交了反馈,但这不是下一个版本的解决方案。

Does anyone know what's the difference between a TestFlight build and an Xcode release build?有谁知道 TestFlight 版本和 Xcode 版本版本之间有什么区别? 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 .我尝试设置不同的优化级别,禁用位码(Apple Watch 应用程序不允许),然后我开始用旧的JSONSerialization替换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.我在 swift 包中遇到了与 Encodable 和 Decodable 非常相似的问题。 Setting DEAD_CODE_STRIPPING = NO in my apps target fixed it.在我的应用程序目标中设置DEAD_CODE_STRIPPING = NO修复了它。 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这似乎是这个错误的一个奇怪的遗留问题: https : //bugs.swift.org/browse/SR-11564?focusedCommentId= 51285&page = com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment- 51285

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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