kfiross / flutter_mongodb_realm

Unofficial Flutter plugin for using MongoDB Realm services on Android, iOS and web.
Apache License 2.0
41 stars 17 forks source link

Error: PlatformException(error, default app can only be set once; currently set to 'MyAppId', null) #13

Closed nksyed closed 3 years ago

nksyed commented 4 years ago

Getting an error after closing the app through the back button on Android, and relaunching the app through recent apps. We assume it's because our main.dart is trying to run MongoStitchClient.initializeApp() again.

nksyed commented 4 years ago

These are the errors we're getting after restarting the app, I replaced the app Id with myAppId:

W/IInputConnectionWrapper(10088): beginBatchEdit on inactive InputConnection W/IInputConnectionWrapper(10088): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper(10088): getTextAfterCursor on inactive InputConnection W/IInputConnectionWrapper(10088): getSelectedText on inactive InputConnection W/IInputConnectionWrapper(10088): endBatchEdit on inactive InputConnection D/EGL_emulation(10088): eglMakeCurrent: 0x749d93846ea0: ver 3 0 (tinfo 0x749d939ee5a0) W/FlutterJNI(10088): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter/textinput. Response ID: 0 W/FlutterJNI(10088): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter/textinput. Response ID: 0 W/ActivityThread(10088): handleWindowVisibility: no activity for token android.os.BinderProxy@5dcbb42 D/EGL_emulation(10088): eglCreateContext: 0x749d93846680: maj 3 min 0 rcv 3 D/ (10088): HostConnection::get() New Host Connection established 0x749d938363c0, tid 10162 D/EGL_emulation(10088): eglMakeCurrent: 0x749d93846680: ver 3 0 (tinfo 0x749d939489a0) D/ (10088): HostConnection::get() New Host Connection established 0x749d99696820, tid 10161 D/EGL_emulation(10088): eglCreateContext: 0x749d91cd99e0: maj 3 min 0 rcv 3 D/EGL_emulation(10088): eglMakeCurrent: 0x749d91cd99e0: ver 3 0 (tinfo 0x749d91d084c0) D/EGL_emulation(10088): eglMakeCurrent: 0x749d93846ea0: ver 3 0 (tinfo 0x749d939ee5a0) E/MethodChannel#flutter_mongo_stitch(10088): Failed to handle method call E/MethodChannel#flutter_mongo_stitch(10088): java.lang.IllegalStateException: default app can only be set once; currently set to 'chexapp-zykko' E/MethodChannel#flutter_mongo_stitch(10088): at com.mongodb.stitch.android.core.Stitch.initializeDefaultAppClient(Stitch.java:175) E/MethodChannel#flutter_mongo_stitch(10088): at com.mongodb.stitch.android.core.Stitch.initializeDefaultAppClient(Stitch.java:149) E/MethodChannel#flutter_mongo_stitch(10088): at com.example.flutter_mongo_stitch.FlutterMongoStitchPlugin.connectMongo(FlutterMongoStitchPlugin.kt:118) E/MethodChannel#flutter_mongo_stitch(10088): at com.example.flutter_mongo_stitch.FlutterMongoStitchPlugin.onMethodCall(FlutterMongoStitchPlugin.kt:76) E/MethodChannel#flutter_mongo_stitch(10088): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226) E/MethodChannel#flutter_mongo_stitch(10088): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#flutter_mongo_stitch(10088): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631) E/MethodChannel#flutter_mongo_stitch(10088): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#flutter_mongo_stitch(10088): at android.os.MessageQueue.next(MessageQueue.java:326) E/MethodChannel#flutter_mongo_stitch(10088): at android.os.Looper.loop(Looper.java:160) E/MethodChannel#flutter_mongo_stitch(10088): at android.app.ActivityThread.main(ActivityThread.java:6669) E/MethodChannel#flutter_mongo_stitch(10088): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter_mongo_stitch(10088): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/MethodChannel#flutter_mongo_stitch(10088): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) D/EGL_emulation(10088): eglMakeCurrent: 0x749d91cd99e0: ver 3 0 (tinfo 0x749d91d084c0) E/flutter (10088): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, default app can only be set once; currently set to 'MyAppId', null) E/flutter (10088): #0 StandardMethodCodec.decodeEnvelope package:flutter/…/services/message_codecs.dart:569 E/flutter (10088): #1 MethodChannel._invokeMethod package:flutter/…/services/platform_channel.dart:156 E/flutter (10088): E/flutter (10088): #2 MethodChannel.invokeMethod package:flutter/…/services/platform_channel.dart:329 E/flutter (10088): #3 MethodChannelFlutterMongoStitch.connectToMongo package:flutter_mongo_stitch_platform_interface/src/method_flutter_mongo_stitch.dart:16 E/flutter (10088): #4 FlutterMongoStitch.connectToMongo package:flutter_mongo_stitch/plugin.dart:15 E/flutter (10088): #5 MongoStitchClient.initializeApp package:flutter_mongo_stitch/mongo_stitch_client.dart:11 E/flutter (10088): #6 main package:chex/main.dart:19 E/flutter (10088): #7 _runMainZoned.. (dart:ui/hooks.dart:241:25) E/flutter (10088): #8 _rootRun (dart:async/zone.dart:1184:13) E/flutter (10088): #9 _CustomZone.run (dart:async/zone.dart:1077:19) E/flutter (10088): #10 _runZoned (dart:async/zone.dart:1619:10) E/flutter (10088): #11 runZonedGuarded (dart:async/zone.dart:1608:12) E/flutter (10088): #12 _runMainZoned. (dart:ui/hooks.dart:233:5) E/flutter (10088): #13 _startIsolate. (dart:isolate-patch/isolate_patch.dart:301:19) E/flutter (10088): #14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

kfiross commented 4 years ago

Hi, I'll try to fix the issue soon, thanks!

Atteprojects commented 4 years ago

Hello, Any fix for the above issue? I am using a try/catch block to check and catch the exception to prevent my app from crashing.

this happens when I do hot reload during development.

is there any other way to check if the MongoStitchClient is initialized without it throwing an error when we reload the app?

`void main() async { WidgetsFlutterBinding.ensureInitialized(); try { await MongoStitchClient.initializeApp("MyApp-Id"); } catch (e) { print(e); }

runApp(MyApp()); }`

kfiross commented 3 years ago

Fixed, will be updated soon