gpt4 book ai didi

sqlite - 在 Android 上后台获取 Flutter 访问数据库

转载 作者:行者123 更新时间:2023-12-03 03:00:57 25 4
gpt4 key购买 nike

我试图在应用程序完全关闭时访问设备上的本地数据库,为此我使用了 sqlite 插件 sqflite: ^1.2.0和后台获取插件background_fetch: ^0.4.0 .

我可以毫无问题地注册 headless 后台任务,当我尝试运行后台任务时,出现以下错误!

当应用程序运行或进入后台模式时,插件似乎工作正常。

请问有什么建议吗?

错误

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method getDatabasesPath on channel com.tekartik.sqflite)

flutter 版本:
Flutter 1.12.13+hotfix.7 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 9f5ff2306b (11 days ago) • 2020-01-26 22:38:26 -0800
Engine • revision a67792536c
Tools • Dart 2.7.0

flutter 医生
[✓] Flutter (Channel stable, v1.12.13+hotfix.7, on Mac OS X 10.15.2 19C57, locale en-GB)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
[✓] Android Studio (version 3.5)
[✓] Connected device (1 available)

• No issues found!

最佳答案

你可以试试看sqflite他们 Github 页面上的故障排除部分,尤其是 the one related to your error .让我把那个页面的内容粘贴到这里。

This error is typically a build/setup error after adding the dependency.

  • Try all the steps defined at the top of the documents
  • Make sure you stop the current running application if any
  • Force a flutter packages get
  • Try to clean your build folder flutter clean
  • On iOS, you can try to force a pod install / pod update
  • Search for other bugs in flutter like this, other people face the same issue with other plugins so it is likely not sqflite related

Advanced checks:

Check the GeneratedPluginRegistrant file that flutter run should have generated in your project contains a line registering the plugin.



安卓:

SqflitePlugin.registerWith(registry.registrarFor("com.tekartik.sqflite.SqflitePlugin"));

IOS:
[SqflitePlugin registerWithRegistrar:[registry registrarForPlugin:@"SqflitePlugin"]];

  • Check MainActivity.java (Android) contains a call to GeneratedPluginRegistrant asking it to register itself. This call should be made from the app launch method (onCreate).


public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}

  • Check AppDelegate.m (iOS) contains a call to GeneratedPluginRegistrant asking it to register itself. This call should be made from the app launch method (application:didFinishLaunchingWithOptions:).

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Before raising this issue, try adding another well established plugin (the simplest being path_provider or shared_preferences) to see if you get the error here as well.

关于sqlite - 在 Android 上后台获取 Flutter 访问数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60118440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com