在通道 plugins.flutter.io/path_provider 上找不到方法 getApplicationDocumentsDirectory 的实现

Posted

技术标签:

【中文标题】在通道 plugins.flutter.io/path_provider 上找不到方法 getApplicationDocumentsDirectory 的实现【英文标题】:No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider 【发布时间】:2020-01-24 14:50:57 【问题描述】:

我的 Flutter 应用程序在初始屏幕上冻结,我收到以下错误日志:

Built build\app\outputs\apk\debug\app-debug.apk.
I/Choreographer(18870): Skipped 75 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation(18870): eglMakeCurrent: 0xe8885480: ver 3 0 (tinfo 0xe88835a0)
I/OpenGLRenderer(18870): Davey! duration=2142ms; Flags=1, IntendedVsync=65263803118670, Vsync=65265053118620, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=65265065657900, AnimationStart=65265065738100, PerformTraversalsStart=65265065780200, DrawStart=65265126086300, SyncQueued=65265197367200, SyncStart=65265199471900, IssueDrawCommandsStart=65265199680700, SwapBuffers=65265651453000, FrameCompleted=65265947767800, DequeueBufferDuration=12659000, QueueBufferDuration=920000,
Syncing files to device android SDK built for x86...
E/flutter (18870): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
Syncing files to device Android SDK built for x86...
E/flutter (18870): <asynchronous suspension>
Syncing files to device Android SDK built for x86...
E/flutter (18870): #1      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:84:22)
Syncing files to device Android SDK built for x86...
E/flutter (18870): <asynchronous suspension>
Syncing files to device Android SDK built for x86...
E/flutter (18870): #2      DbContext.initDb (package:appentrega/database.dart:34:45)
Syncing files to device Android SDK built for x86...
E/flutter (18870): <asynchronous suspension>
Syncing files to device Android SDK built for x86...
E/flutter (18870): #3      DbContext.getContext (package:appentrega/database.dart:27:21)
Syncing files to device Android SDK built for x86...
E/flutter (18870): <asynchronous suspension>
Syncing files to device Android SDK built for x86...
E/flutter (18870): #4      _SplashScreenState.startTime (package:appentrega/splash.dart:16:34)
Syncing files to device Android SDK built for x86...
E/flutter (18870): <asynchronous suspension>
Syncing files to device Android SDK built for x86...
E/flutter (18870): #5      _SplashScreenState.initState (package:appentrega/splash.dart:33:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #6      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4068:58)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #7      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #8      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #9      Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #10     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5127:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3961:16)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #14     Element.rebuild (package:flutter/src/widgets/framework.dart:3738:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #15     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3924:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #16     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #17     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #18     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #19     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5127:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #20     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #21     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #22     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5127:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #23     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #24     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #25     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5127:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #26     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #27     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #28     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5127:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #29     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #30     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #31     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3961:16)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #32     Element.rebuild (package:flutter/src/widgets/framework.dart:3738:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #33     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3924:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #34     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4088:11)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #35     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #36     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #37     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #38     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3961:16)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #39     Element.rebuild (package:flutter/src/widgets/framework.dart:3738:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #40     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3924:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #41     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #42     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #43     Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
Syncing files to device Android SDK built for x86...
E/flutter (18870): #44
Syncing files to device Android SDK built for x86...
D/EGL_emulation(18870): eglMakeCurrent: 0xe8885720: ver 3 0 (tinfo 0xe88832f0)
Syncing files to device Android SDK built for x86...
 4.034ms (!)

看起来问题出在这里: [错误:flutter/lib/ui/ui_dart_state.cc(148)] 未处理的异常:MissingPluginException()

已经这样做了:

-删除所有插件并重新安装flutter pub get。 -运行flutter cleanflutter run

【问题讨论】:

【参考方案1】:

此错误通常发生在您获得插件但未再次构建应用程序时。如果这是您在 pubspec.yaml 上获取插件后的情况,请重新安装您的 apk。如果这不是您的问题,您是否创建了支持 kotlin 和 swift 的项目?我不知道是不是这样,但大多数插件都需要这个

【讨论】:

我真的不知道发生了什么,我通过从git中提取以前的代码并替换我已经更新的代码来解决它。可能搞砸了一些深层的 android 文件或类似的东西,没有线索。 我在尝试使用 Flutter Desktop Windows 构建我的项目时遇到了同样的错误。尝试了一个新的 git repo pull 和 flutter clean 但仍然没有乐趣。在模拟器上运行良好,只是在 Windows 上出现错误。 这个答案意味着该插件在androidobj-c or swift 上包含平台代码java or kotlin,并且这些不会从缓存中提取hot reloadhot restart 你需要做的完整的应用程序 rebuildflutter runflutter build,具体取决于您的开发或部署【参考方案2】:

在构建发行版 apk 后,我收到另一个插件的此错误, 这是因为默认情况下启用了代码收缩 - 如果您不想缩小/混淆代码,只需在 android/app/build.gradle 中添加两行。

android 
    ...

    buildTypes 
        release 
            ...
         
            shrinkResources false
            minifyEnabled false
        
    

【讨论】:

这对我有用。我遇到了 PathProvider 缺少实现的问题。添加上述2行并生成一个app-bundle后,问题就解决了。请注意这个问题在 Android 和 ios 的模拟器上没有发生。它仅在创建应用程序包后发生。【参考方案3】:

Flutter 网页版

我在开始向应用程序添加 Web 支持后遇到了这个问题。 getApplicationDocumentsDirectory() 函数仅支持 iOS 和 Android (docs)。我添加了一个网络检查并更改了设置目录的方式,为我修复了“找不到方法的实现”。

要判断平台是否为 web,请使用 Flutter 的 kIsWeb:

import 'package:flutter/foundation.dart' show kIsWeb;

然后相应地处理设置目录:

if (kIsWeb) 
    // Set web-specific directory
 else 
    appDocumentDirectory = await path_provider.getApplicationDocumentsDirectory();

【讨论】:

谢谢,这个错误现在似乎再次出现,更可能的情况是在 beta 和非常新的情况下简单地使用 Flutter Web 网络特定目录应该使用什么路径? @Meggy 你找到解决办法了吗? 导入 'package:flutter/foundation.dart' 显示 kIsWeb; if (!kIsWeb) //path only for android and ios final appDocumentDirectory = await path_provider.getApplicationDocumentsDirectory(); Hive.init(appDocumentDirectory.path); 我使用数据库示例,它在 _initDatabase() 处使用 getApplicationDocumentsDirectory(),需要更改。我会搬到楼层:levelup.gitconnected.com/…【参考方案4】:

原来我不得不退出颤振运行过程并重新启动它。只是在颤振运行中完全重启是行不通的。

这里是参考链接https://github.com/flutter/flutter/issues/10912

编辑:一定要导入这些包;

    package:path_provider/path_provider.dart 飞镖:io 飞镖:异步

【讨论】:

这为我节省了很多时间。每当怀疑某个包不起作用时,只需退出运行过程并重新启动它就可以解决问题。【参考方案5】:

如果你的包依赖于flutter_facebook_auth,你需要确保你已经对Android和iOS进行了设置以消除错误。我正在使用 Hive 和 Facebook 登录,令人惊讶的是,缺少 Facebook 设置导致 Hive.initFlutter() 抛出此错误。

即使您实际上没有在 Facebook 开发者帐户上设置 Facebook 应用程序,此修复程序也将起作用。

【讨论】:

谢谢伙计!我一下子想不通到底发生了什么。感谢您的回答,我可以联系并考虑解决方案。 谢谢兄弟,问题是facebook插件我真的不知道flutter和facebook插件有什么问题【参考方案6】:

你只需要重新安装应用程序

您可以使用https://pub.dev/packages/permission_handler runtime 管理权限

通常,当您在 AndroidManifest.xml 文件中提及权限时,它会在应用第一次启动时请求权限,这就是您需要重新安装应用或从权限管理器授予权限的原因,或者您可以使用上述软件包从您的应用动态处理它

【讨论】:

【参考方案7】:

对我有用的是在Application.java(或Application.kt)中注册相应的插件方法通道。所以是这样的:

package com.example.lifely;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.pathprovider.PathProviderPlugin;

public class Application extends FlutterApplication implements PluginRegistrantCallback 
  @Override
  public void registerWith(PluginRegistry registry) 
    PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"));
  

【讨论】:

【参考方案8】:

就我而言,我没有包含 dart:async 包。运行“flutter run”并包含“dart:async”包解决了问题

【讨论】:

【参考方案9】:

在我的情况下是缓存,我已经删除了 cached_network_image 并将其替换为 Image.network 并且问题已经消失了

【讨论】:

【参考方案10】:

在我的例子中,我的 AndroidManifest.xml 文件中缺少下面的 sn-p。

        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

在 AndroidManifest.xml 文件中添加它可以解决问题。

【讨论】:

【参考方案11】:

升级-pre-1.12-Android-projects 后!!

如果您没有太多时间尝试编辑步骤 5 的 AppDelegate.h

我按照指南更新后通过:Upgrading-pre-1.12-Android-projects 应用以​​下操作:

    将颤振更新到其最新的稳定版本 -> 缺少颤振清洁

    更新你所有的依赖(很可能包有或要求你添加新方法)->flutter clean 并不过分

    更新包更新产生的代码和方法

    尝试 flutter run 或从 android Studio |> (某些包可能会向您发送missingPluginException,但如果它已安装在移动设备上)请转到第 5 步。

    如果可以的话,为 android 和 IOS 构建测试安装(它们应该可以正常工作)。 很可能在使用颤振运行的开发中,它会继续发送错误,在我的情况下,我无法在 IOS 中进行测试,但使用颤振运行它可以同时为 android 和 IOS 运行,并且通过将其添加到 ios / Runner / AppDelegate 来解决问题。 h ->[GeneratedPluginRegistrant registerWithRegistry: self];

    #import #import

    @interface AppDelegate: FlutterAppDelegate [GeneratedPluginRegistrant registerWithRegistry: self]; @EnD

如果在这些步骤之后无法在步骤 4 0 5 中执行,请确认其他依赖项尚未更新其版本以兼容 Upgrading-pre-1.12-Android-projects !。例如 cached_network_image 使用 path_provider 尝试卸载 cached_network_image 包 再次从第 4 步开始重复。

【讨论】:

你可以清楚地看到这是一个android问题而不是iOS

以上是关于在通道 plugins.flutter.io/path_provider 上找不到方法 getApplicationDocumentsDirectory 的实现的主要内容,如果未能解决你的问题,请参考以下文章

在通道变量初始化后建立缓冲通道

如何在png里删除alpha通道

先建立控制通道,再建立数据通道会引起的问题。

无法装入传输通道

信号 goroutine 在通道关闭时停止

如何在不更改其他通道的情况下有效地将 cv::Mat 的给定通道设置为给定值?