Fabio Dias
Fabio Dias

Reputation: 1406

No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider

My Flutter application is freezing on the splash screen and I'm getting the following error log:

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 (!)

Looks like the problem is here: [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)

Already done this:

-Deleted all plugins and reinstalled with flutter pub get.
-Runned flutter clean and flutter run

Upvotes: 50

Views: 95259

Answers (17)

Dr. Sarah
Dr. Sarah

Reputation: 21

The only thing that worked for me was to delete the cache at %USERPROFILE\AppData\Local\Pub\Cache\hosted\pub.dev\path_provider-2.1.2

To be thorough, I also did

flutter clean
flutter pub remove path_provider
flutter pub add path_provider
flutter run -d windows

And it finally works!

Upvotes: 0

  1. import 'package:path_provider/path_provider.dart';
    
      Future<Directory?>? _externalDocumentsDirectory;
    
      void _requestAppDocumentsDirectory() {
        setState(() {
          _externalDocumentsDirectory = getExternalStorageDirectory();
        });
      }
    
      Widget _buildDirectory(
            BuildContext context, AsyncSnapshot<Directory?> snapshot) {
          Text text = const Text('');
          if (snapshot.connectionState == ConnectionState.done) {
            if (snapshot.hasError) {
              text = Text('Error: ${snapshot.error}');
            } else if (snapshot.hasData) {
              text = Text('path: ${snapshot.data!.path} ');
    
              print(snapshot.data!.path); //
              createExcel(snapshot.data!.path); // I send a string with the route
            } else {
              text = const Text('path unavailable');
            }
          }
          return Padding(padding: const EdgeInsets.all(16.0), child: text);
        }
    
ElevatedButton(
               style: ButtonStyle(
               backgroundColor: MaterialStateProperty.all(
                 const Color.fromARGB(255, 39, 136, 42),
                ),
               ),
               onPressed: _requestAppDocumentsDirectory,
               child: const Text(
                 'Exportar contraseñas',
                ),
               ),
             FutureBuilder<Directory?>(
               future: _externalDocumentsDirectory,
               builder: _buildDirectory,
             ),

enter image description here

More information in the library documentation: https://pub.dev/packages/path_provider/example

Upvotes: 0

Karolina Hageg&#229;rd
Karolina Hageg&#229;rd

Reputation: 1387

I had this error ("MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)") in an old app that I had to run with flutter run --ignore-deprecation, because it was using an old Android embedding and I didn't want to migrate it just now.

But it worked out, because I removed this line from my app/src/main/AndroidManifest.xml file:

android:name="io.flutter.app.FlutterApplication"

and magically, the error disappeared! 🙂

Hope it helps someone else, as well.

Upvotes: 0

januarvs
januarvs

Reputation: 408

With these codes, I got same error with web. It works for Windows.

import 'package:path_provider/path_provider.dart';
...
  final document = await getApplicationDocumentsDirectory();
  Hive.init(document.path);

Replacing it with Hive.initFlutter() looks cover it all (Windows, web, and Android):

import 'package:hive_flutter/hive_flutter.dart';
...
  await Hive.initFlutter();

PS: I haven't tried on iOS, but should work too.

Upvotes: 0

Usama Karim
Usama Karim

Reputation: 1428

As the Flutter team working on Dart plugin registration doesn't run in background isolates #98591 for adopting in-package platform channels in more 1P plugins, which requires Dart plugin registration, the plugins do not work in Isolates out of the box, The work is still in the progress after the completion you'll need to initialize DartPluginRegistrant.ensureInitialized() as WidgetsFlutterBinding.ensureInitialized() before.

Until then there is a workaround for it. #99155

The workaround described there will work for path_provider as well:

Add dependencies on path_provider_android and path_provider_ios. At the beginning of your background isolate entry point, add something like:

if (Platform.isAndroid) PathProviderAndroid.registerWith();
if (Platform.isIOS) PathProviderIOS.registerWith();

Upvotes: 3

Matt Meades
Matt Meades

Reputation: 41

Had this error while using cached_network_image on a Flutter MacOS desktop app - think it was caused by the 2.0.0 update of path_provider package:

Screenshot of path_provider changelogs for 2.0.0

I think because the path_provider function that cached_network_image uses (getTemporaryDirectory()) doesn't have paths defined on desktop, this causes it to throw the error.

Screenshot from path_provider package docs

To solve this (in my case), I imported the path_provider_macos package (https://pub.dev/packages/path_provider_macos) and registered it in main before my app started up.

void main() {
  PathProviderMacOS.registerWith();
  runApp(MyApp());
}

I haven't tested other platforms but packages exist for linux (https://pub.dev/packages/path_provider_linux) and windows (https://pub.dev/packages/path_provider_windows) so should hopefully fix the issue on these platforms as well.

Upvotes: 1

Code on the Rocks
Code on the Rocks

Reputation: 17596

If your package depends on flutter_facebook_auth, you need to make sure you have performed the setup for Android and iOS to get rid of the error. I was using Hive and Facebook login and surprisingly, the missing Facebook setup was causing Hive.initFlutter() to throw this error.

This fix will work even if you don't actually have the Facebook app setup on your Facebook Developers account.

Upvotes: 7

Dev vora
Dev vora

Reputation: 111

You just need to reinstall app

OR

You can manage permissions using https://pub.dev/packages/permission_handler runtime

generally when you mention permissions in AndroidManifest.xml file it asks for permission when app starts for first time that's why you need to reinstall app or give permissions from permission manager or you can handle it from your app dynamically using above package

Upvotes: 4

Nico
Nico

Reputation: 197

What worked for me is register the corresponding plugin method channel in the Application.java(or Application.kt). So it's this:

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"));
  }
}

Upvotes: 3

Owen
Owen

Reputation: 905

Flutter for Web

I ran into this after starting to add web support to an application. The getApplicationDocumentsDirectory() function only supports iOS and Android (docs). I added a check for web and changed the way I set the directory which fixed the "No implementation found for method" for me.

To tell if the platform is web use Flutter's kIsWeb:

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

Then handle setting the directory accordingly:

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

Upvotes: 46

Uriel Manzano
Uriel Manzano

Reputation: 11

After Upgrading-pre-1.12-Android-projects !!

if you don't have a lot of time trying editing AppDelegate.h of step 5

I pass after updating by following the guide: Upgrading-pre-1.12-Android-projects apply the following actions:

  1. Update flutter to its latest stable version -> flutter clean is missing

  2. Update all your dependencies (it is very likely that packages have or ask you to add new methods) -> flutter clean is not too much

  3. Update the code and methods resulting from the package update

  4. Try flutter run or from android Studio |> (some packages may send you missingPluginException but if it is installed on the mobile) go to step 5.

  5. Build the test installs for android and IOS if you can (they should work fine). It is likely that in development with flutter run it continues to send the error, in my case I cannot test in IOS but with flutter run it runs for both android and IOS and the problem is solved by adding it to ios / Runner / AppDelegate.h ->[GeneratedPluginRegistrant registerWithRegistry: self];

    #import <Flutter / Flutter.h> #import <UIKit / UIKit.h>

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

If after these steps it cannot be executed in step 4 0 5, verify that other dependencies have not updated their versions to be compatible with Upgrading-pre-1.12-Android-projects !. For example cached_network_image uses path_provider try uninstalling the cached_network_image package Repeat from step 4 again.

Upvotes: -1

Akinola Olayinka
Akinola Olayinka

Reputation: 861

In my case, the snippet below was missing from my AndroidManifest.xml file.

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

Adding it in the AndroidManifest.xml file fixed the problem.

Upvotes: 1

Ramees Thattarath
Ramees Thattarath

Reputation: 1093

I got this error for a different plugin after I build the release apk, this was because code shrinking is enabled by default - if you don't want to minify/obfuscate code just add the two lines inside android/app/build.gradle.

android {
    ...

    buildTypes {
        release {
            ...
         
            shrinkResources false
            minifyEnabled false
        }
    }
}

Upvotes: 36

NBM
NBM

Reputation: 1036

In my case, I haven't included dart:async package. Running "flutter run" and including "dart:async" package resolved the problem

Upvotes: 1

Ricardo
Ricardo

Reputation: 2291

In my case it was for the cache, I have removed cached_network_image and replaced it with Image.network and the problem has disappeared

Upvotes: 0

user13173890
user13173890

Reputation:

Turned out I had to quit the flutter run process and start it up again. Just a full restart within flutter run didn't work.

Here is a link for reference https://github.com/flutter/flutter/issues/10912

Edit: Be sure you import these packages;

  1. package:path_provider/path_provider.dart
  2. dart:io
  3. dart:async

Upvotes: 6

Rodrigo Bastos
Rodrigo Bastos

Reputation: 2448

This error generally occur when you get a plugin and not build the app again. If this is your case after getting the plugin on pubspec.yaml reinstall your apk. If this is not your problem did you created your project with suport for kotlin and swift? I don't know if this is the case but most of the plugins need this

Upvotes: 71

Related Questions