tekartik / sqflite

SQLite flutter plugin
BSD 2-Clause "Simplified" License
2.86k stars 524 forks source link

Android API 35 MissingPluginException #1119

Open KERRAT opened 1 month ago

KERRAT commented 1 month ago

When executing the following code with API level 35:

join(await sqlflite.getDatabasesPath(), DATABASE_NAME)

The application encounters the following error and stack trace:

[  +17 ms] E/flutter ( 5012): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method getDatabasesPath on channel com.tekartik.sqflite)
[        ] E/flutter ( 5012): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
[        ] E/flutter ( 5012): <asynchronous suspension>
[        ] E/flutter ( 5012): #1      invokeMethod (package:sqflite/src/sqflite_impl.dart:16:5)
[        ] E/flutter ( 5012): <asynchronous suspension>
[        ] E/flutter ( 5012): #2      wrapDatabaseException (package:sqflite/src/exception_impl.dart:7:20)
[        ] E/flutter ( 5012): <asynchronous suspension>
[        ] E/flutter ( 5012): #3      SqfliteDatabaseFactoryMixin.getDatabasesPath (package:sqflite_common/src/factory_mixin.dart:182:20)

However, when running the same code on an API level 34 emulated device, no errors are encountered. There are no differences between the builds used for both tests.

Used sqlflite version is 2.3.3+1.

alextekartik commented 1 month ago

Are you calling this in your main() function or before calling runApp. If so are you calling WidgetsFlutterBinding.ensureInitialized(); before ? Does it work with other plugin (such as path_provider)?

KERRAT commented 1 month ago

@alextekartik , this is called deep after runApp.

WidgetsFlutterBinding.ensureInitialized(); is called right before join(await sqlflite.getDatabasesPath(), DATABASE_NAME), to avoid such errors.

Yes, there is some strange behaviour for Path Provider as well:

[+3966 ms] E/flutter ( 3505): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
[        ] E/flutter ( 3505): #0      PathProviderApi.getApplicationSupportPath (package:path_provider_android/messages.g.dart:65:7)
[        ] E/flutter ( 3505): <asynchronous suspension>
[        ] E/flutter ( 3505): #1      getApplicationSupportDirectory (package:path_provider/path_provider.dart:78:24)
[        ] E/flutter ( 3505): <asynchronous suspension>

Retested on API 34, there are no errors neither for sqlite nor path_provider_android

alextekartik commented 1 month ago

If even path_provider is failing, I won't look at it yet. I try to stick with the compileSdk used my google flutter plugins. I'm not sure sdk 35 is officially supported at this point.