Closed JanSob closed 1 year ago
Your call stacks is not symbolized so it's impossible to investigate any further. You should use Xcode to run the application and set a ObjC exception breakpoint to catch the call stacks.
I believe when you do catch that, you could figure the problem out by yourself.
Hmm..this is the callstack, I am not really sure why mmkv is not initialized though; it's literally the fist thing that should happen..
2023-05-25 19:19:15.420788+0200 Runner[24316:2602011] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'MMKV not initialized properly, must call +initializeMMKV: in main thread before calling any other MMKV methods'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ab208cb __exceptionPreprocess + 242
1 libobjc.A.dylib 0x000000010a7b7ba3 objc_exception_throw + 48
2 Foundation 0x000000010f78137c _userInfoForFileAndLine + 0
3 MMKV 0x000000010944e7be +[MMKV mmkvWithID:cryptKey:rootPath:mode:] + 126
4 MMKV 0x000000010944e4ca +[MMKV mmkvWithID:] + 58
5 Runner 0x00000001000f4a35 $sSo4MMKVC6mmapIDABSgSS_tcfCTO + 53
6 Runner 0x0000000100103f8c $sSo9OS_os_logC6RunnerE4mmkv33_ED9F07FBD337E3DDAD7A887565697ED4LL_WZ + 60
7 libdispatch.dylib 0x000000010b9e8f5b _dispatch_client_callout + 8
8 libdispatch.dylib 0x000000010b9ea5b5 _dispatch_once_callout + 66
9 Runner 0x0000000100103fd1 $sSo9OS_os_logC6RunnerE4mmkv33_ED9F07FBD337E3DDAD7A887565697ED4LLSo4MMKVCSgvau + 49
10 Runner 0x000000010010480f $sSo9OS_os_logC6RunnerE8storeLog33_ED9F07FBD337E3DDAD7A887565697ED4LL7messageySS_tFZ + 79
11 Runner 0x0000000100104ae4 $sSo9OS_os_logC6RunnerE0C0_AD4typeySS_ABSo0b1_c1_E2_tatFZ + 468
12 Runner 0x0000000100113a15 $s6Runner13BeaconMonitorC25startMonitoringIfPossible16isBackgroundModeySb_tF + 277
13 Runner 0x00000001000f81d8 $s6Runner11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtF + 616
14 Runner 0x00000001000f8587 $s6Runner11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtFTo + 183
15 UIKitCore 0x00000001260c31bb -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 271
16 UIKitCore 0x00000001260c505f -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 4257
17 UIKitCore 0x00000001260cae3b -[UIApplication _runWithMainScene:transitionContext:completion:] + 1236
18 UIKitCore 0x00000001254fe098 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 122
19 UIKitCore 0x0000000125b7036d _UIScenePerformActionsWithLifecycleActionMask + 88
20 UIKitCore 0x00000001254feb92 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 198
21 UIKitCore 0x00000001254fe5cf -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 252
22 UIKitCore 0x00000001254fe9c8 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 831
23 UIKitCore 0x00000001254fe275 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 354
24 UIKitCore 0x000000012550d0e1 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 178
25 UIKitCore 0x0000000125a41363 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 833
26 UIKitCore 0x0000000125b8e42f _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 257
27 UIKitCore 0x000000012550cd61 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 348
28 UIKitCore 0x00000001252eff16 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.594 + 815
29 UIKitCore 0x00000001252ee92c -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 245
30 UIKitCore 0x00000001252efac3 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 255
31 UIKitCore 0x00000001260c9641 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 733
32 UIKitCore 0x0000000125a73c73 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 350
33 FrontBoardServices 0x000000010ccfb41b -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 415
34 FrontBoardServices 0x000000010cd29583 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.187 + 102
35 FrontBoardServices 0x000000010cd0946a -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 209
36 FrontBoardServices 0x000000010cd29178 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 344
37 libdispatch.dylib 0x000000010b9e8f5b _dispatch_client_callout + 8
38 libdispatch.dylib 0x000000010b9ec8d2 _dispatch_block_invoke_direct + 496
39 FrontBoardServices 0x000000010cd4f980 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
40 FrontBoardServices 0x000000010cd4f876 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 174
41 FrontBoardServices 0x000000010cd4f9a8 -[FBSSerialQueue _performNextFromRunLoopSource] + 19
42 CoreFoundation 0x000000010aa80035 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
43 CoreFoundation 0x000000010aa7ff74 __CFRunLoopDoSource0 + 157
44 CoreFoundation 0x000000010aa7f771 __CFRunLoopDoSources0 + 212
45 CoreFoundation 0x000000010aa79e73 __CFRunLoopRun + 927
46 CoreFoundation 0x000000010aa796f7 CFRunLoopRunSpecific + 560
47 GraphicsServices 0x000000010cf5628a GSEventRunModal + 139
48 UIKitCore 0x00000001260c762b -[UIApplication _run] + 994
49 UIKitCore 0x00000001260cc547 UIApplicationMain + 123
50 Runner 0x00000001000f898f main + 63
51 dyld 0x00000001090eb2bf start_sim + 10
52 ??? 0x0000000200b4d41f 0x0 + 8601785375
)
libc++abi: terminating with uncaught exception of type NSException
Message from debugger: Terminated due to signal 6
Maybe because the so-called main function of your dart code is not actually the main function of an iOS application. You can add a log just before you called MMKV.initialize() and you should probably see it's not printed.
Maybe because the so-called main function of your dart code is not actually the main function of an iOS application. You can add a log just before you called MMKV.initialize() and you should probably see it's not printed.
I will try to find the correct native call to MKKV.initialize and await it in 'AppDelegate'. Thank you for the hint!
I was able to fix the bug, the App works now. If anyone ever stumbles upon this issue with the Flutter Plugin, here is a possible solution to await MMKV to initialize in AppDelegate.swift by using DispatchQueue:
import UIKit
import Flutter
import Foundation
import CoreBluetooth
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
initializeMMKV {
// additional function-calls
ServiceSetup(controller.binaryMessenger,ServiceImpl())
ConfigStore.shared.initializeInstanceId()
Monitor.shared.startMonitoringIfPossible()
TokenStore.shared.getUpdatedToken()
GeneratedPluginRegistrant.register(with: self)
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// Using DispatchQueue
func initializeMMKV(completion: @escaping () -> Void) {
DispatchQueue.main.async {
MMKV.initialize(rootDir: nil) {
completion()
}
}
}
}
The language of MMKV
Dart
The version of MMKV
v1.2.7
The platform of MMKV
(Flutter) iOS
The installation of MMKV
Flutter plugin // Cocoapods
1/4 What's the issue?
The App crashes immediately after starting it, both on a physical device and on the simulator (iOS). The app runs perfectly fine on Android. The first thing i do on main in dart is to call 'await MMKV.initialize();',
2/4. This is the error-log:
3/4. This is the main-function in Flutter:
4/4. This is the Podfile
5/5 GeneratedPluginRegistrant.m