我的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(在通道plugins.flutter.io/path_provider上未找到方法getApplicationDocumentsDirectory的实现)
已经做到了:
-删除了所有插件,并使用flutter pub get
重新安装。
-运行的flutter clean
和flutter run
答案 0 :(得分:4)
Flutter for Web
在开始向应用程序添加Web支持之后,我遇到了这个问题。 getApplicationDocumentsDirectory()函数仅支持iOS和Android (docs)。我添加了一个针对Web的检查,并更改了设置目录的方式,该目录为我修复了“找不到方法的实现”。
要判断平台是否为Web,请使用Flutter的kIsWeb:
import 'package:flutter/foundation.dart' show kIsWeb;
然后处理相应地设置目录:
if (kIsWeb) {
// Set web-specific directory
} else {
appDocumentDirectory = await path_provider.getApplicationDocumentsDirectory();
}
答案 1 :(得分:3)
当您获得一个插件并且不再重新构建应用程序时,通常会发生此错误。如果是这种情况,请在pubspec.yaml上获取插件后,重新安装apk。如果这不是您的问题,您是否使用kotlin和swift的suport创建了项目?我不知道是否是这种情况,但是大多数插件都需要
答案 2 :(得分:2)
原来,我不得不退出flutter运行过程,然后再次启动。只是在颤动下完全重启是行不通的。
这里是参考链接https://github.com/flutter/flutter/issues/10912
编辑:请确保您导入了这些软件包;
答案 3 :(得分:2)
对我有用的是在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"));
}
}
答案 4 :(得分:2)
如果您的软件包依赖于 flutter_facebook_auth,您需要确保您已经为 Android 和 iOS 执行了设置以消除错误。我正在使用 Hive 和 Facebook 登录,但令人惊讶的是,缺少 Facebook 设置导致 Hive.initFlutter() 抛出此错误。
即使您的 Facebook 开发者帐户中实际上没有设置 Facebook 应用程序,此修复程序也会起作用。
答案 5 :(得分:1)
我在构建发行版APK后收到了针对其他插件的错误消息, 这是因为默认情况下启用了代码收缩功能-如果您不想缩小/混淆代码,只需在android / app / build.gradle中添加两行即可。
android {
...
buildTypes {
release {
...
shrinkResources false
minifyEnabled false
}
}
}
答案 6 :(得分:1)
您只需要重新安装应用程序
或
您可以使用 https://pub.dev/packages/permission_handler 运行时管理权限
通常,当您在 AndroidManifest.xml 文件中提到权限时,它会在应用首次启动时请求权限,这就是您需要重新安装应用或从权限管理器授予权限的原因,或者您可以使用上述包从您的应用动态处理它>
答案 7 :(得分:0)
在我的缓存中,我删除了cached_network_image并将其替换为Image.network,问题消失了
答案 8 :(得分:0)
就我而言,我没有包括dart:async包。运行“ flutter run”并包含“ dart:async”包即可解决问题
答案 9 :(得分:0)
对于我来说,我的AndroidManifest.xml文件中缺少以下代码段。
<meta-data
android:name="flutterEmbedding"
android:value="2" />
将其添加到AndroidManifest.xml文件中即可解决此问题。
答案 10 :(得分:0)
在1.12之前的Android项目升级后!!
如果您没有太多时间尝试编辑步骤5的AppDelegate.h
我在更新后通过遵循以下指南:Upgrading-pre-1.12-Android-projects进行以下操作:
将flutter更新到其最新的稳定版本-> flutter clean丢失
更新所有依赖项(软件包很可能具有或要求您添加新方法)->清理干净不是太多
更新由软件包更新产生的代码和方法
尝试运行flutter或从android Studio |>(某些程序包可能会向您发送missingPluginException,但如果它已安装在移动设备上),请转到步骤5。
如果可以的话,构建适用于android和IOS的测试安装(它们应该工作正常)。 在使用flutter运行的开发中,它很可能继续发送错误,在我的情况下,我无法在IOS中进行测试,但是使用flutter run,它可以同时在android和IOS上运行,并且可以通过将其添加到ios / Runner / AppDelegate来解决问题。 h-> [GeneratedPluginRegistrant registerWithRegistry:self];
#import
@interface AppDelegate:FlutterAppDelegate [GeneratedPluginRegistrant registerWithRegistry:self]; @EnD
如果在这些步骤之后无法在步骤4 0 5中执行,请验证其他依赖项是否未更新其版本以与Upgradeing-1.12-Android-projects!兼容。例如,cached_network_image使用path_provider尝试卸载cached_network_image软件包 再次从第4步开始重复。
答案 11 :(得分:0)
转到项目位置的终端,然后输入以下命令
flutter clean
然后重新运行项目。这对我有用