Skip to content

Trouble with using path_provider package in an isolate  #51685

Closed

Description

@Drkstr

Issue description:

I am using the flutter_isolate package to spawn an isolate. When I try to call getApplicationDocumentsDirectory() in the isolate I get the following error.

Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)

flutter doctor -v

[✓] Flutter (Channel beta, v1.14.6, on Mac OS X 10.15.3 19D76, locale en-AU)
• Flutter version 1.14.6 at /Users/drkstr/development/flutter
• Framework revision fabeb2a (5 weeks ago), 2020-01-28 07:56:51 -0800
• Engine revision c4229bf
• Dart version 2.8.0 (build 2.8.0-dev.5.0 fc3af737c7)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)

• Android SDK at /Users/drkstr/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = /Users/drkstr/Android/Sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)

• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4

[✓] Chrome - develop for the web

• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.5)

• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[!] VS Code (version 1.42.1)

• VS Code at /Applications/Visual Studio Code.app/Contents
✗ Flutter extension not installed; install from
  https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)

• Pixel XL   • HT74T0205374 • android-arm64  • Android 10 (API 29)
• Chrome     • chrome       • web-javascript • Google Chrome 80.0.3987.122
• Web Server • web-server   • web-javascript • Flutter Tools

! Doctor found issues in 1 category.

pubspec.yaml file

name: tablet_tests
description: Application to test tablet functionality
version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
usb_serial: 0.2.3
flutter_isolate: 1.0.0+11
provider: 4.0.1
flutter_secure_storage: 3.3.1+1
sqflite: 1.2.0
path_provider: 1.6.1
path: 1.6.4

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true

stacktrace

E/flutter (11692): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)
E/flutter (11692): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
E/flutter (11692):
E/flutter (11692): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter (11692): #2 getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:92:22)
E/flutter (11692): #3 DatabaseSingleton.initDB (package:tablet_tests/singletons/DatabaseSingleton.dart:31:42)
E/flutter (11692): #4 DatabaseSingleton.database (package:tablet_tests/singletons/DatabaseSingleton.dart:25:36)
E/flutter (11692): #5 DatabaseSingleton.insertLog (package:tablet_tests/singletons/DatabaseSingleton.dart:40:22)
E/flutter (11692): #6 backgroundTask (package:tablet_tests/background_processes/BackgroundStuff.dart:11:8)
E/flutter (11692): #7 isolate1 (package:tablet_tests/main.dart:10:3)
E/flutter (11692): #8 FlutterIsolate._isolateInitialize.. (package:flutter_isolate/flutter_isolate.dart:128:23)
E/flutter (11692): #9 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (11692): #10 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (11692): #11 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (11692): #12 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (11692): #13 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
E/flutter (11692): #14 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:773:19)
E/flutter (11692): #15 _StreamController._add (dart:async/stream_controller.dart:649:7)
E/flutter (11692): #16 _StreamController.add (dart:async/stream_controller.dart:595:5)
E/flutter (11692): #17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

The output of flutter run --verbose:
https://drive.google.com/open?id=1heTLOyNBqSR13jv8MzLOj6sb2whjEQcK01KbRnxHzz4

Minimal app to reproduce the error:
https://drive.google.com/open?id=1eWJguDVGzyeuzvhReQVHb1i8uIEmSX6A

To reproduce the error download and run the minimal app I have linked above.

Let me know if you would like any more info.

Activity

  1. VladyslavBondarenko commented on Mar 17, 2020

    @VladyslavBondarenko

    Related to #46679

  2. tiagoantunes commented on Jun 26, 2020

    @tiagoantunes

    A possible related issue, #59683 (comment).

  3. oligazar commented on Jan 29, 2021

    @oligazar

    Same problem here. Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider) when running getApplicationDocumentsDirectory() in isolate.

    Is there any solution or clue how to handle that?

  4. oligazar commented on Jan 29, 2021

    @oligazar

    Same problem here. Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider) when running getApplicationDocumentsDirectory() in isolate.

    Is there any solution or clue how to handle that?

    I manage to work around this issue registering plugins manually in Application.kt

    class Application : FlutterApplication(), PluginRegistrantCallback {
        override fun onCreate() {
            super.onCreate()
            LocatorService.setPluginRegistrant(this)
            FlutterMain.startInitialization(this)
        }
        
        override fun registerWith(registry: PluginRegistry?) {
            if (!registry!!.hasPlugin("io.flutter.plugins.pathprovider")) {
                PathProviderPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.pathprovider"))
            }
        }
    }
    
  5. added
    P3Issues that are less important to the Flutter project
    on Apr 1, 2021
  6. One-djey commented on Dec 2, 2021

    @One-djey

    The @oligazar workaround isn't suitable for me and I'm still experiencing the error:

    Null check operator used on a null value
    I/flutter (11969): #0      MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142:86)
    I/flutter (11969): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148:36)
    I/flutter (11969): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12)
    I/flutter (11969): #3      MethodChannelPathProvider.getApplicationDocumentsPath (package:path_provider_platform_interface/src/method_channel_path_provider.dart:50:10)
    I/flutter (11969): #4      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:138:40)
    

    When I call Directory appDocDir = await getApplicationDocumentsDirectory(); from package package:path_provider/path_provider.dart in an Isolate.

  7. krunalgajera98 commented on Feb 7, 2022

    @krunalgajera98

    Hi, @Drkstr same Issue here, can you please tell me how you solve this error, any help would be appreciated
    thanks!

  8. Drkstr commented on Feb 23, 2022

    @Drkstr
    Author

    @krunalgajera98 I never found a workaround for this. I ended up rearchitecting the app to not need isolates.

  9. brunodmn commented on Mar 4, 2022

    @brunodmn

    Similar here, when trying to use use it with workmanager on iOS.
    In my mainframe I can inject and use the path_provider, but when I trigger it from workmanager it wont work at all. Already tried flutter clean/get, flutter pub cache repair, close and reopen emulator and IDE..nothing works.

    Here is a minimum code to reproduce: link
    1 - created new flutter project
    2 - added packages workamanager/path_provider
    3 - initialized workmanager and setup iOS especific configuration
    4 - opened xcode, ran the project then selected debug>simulate background fetch
    5 - expected to see successful return with path created, but actually see MissingPluginException(No implementation found for method getTemporaryDirectory on channel plugins.flutter.io/path_provider)

    Someone knows how can I manually initialize the plugin on my AppDelegate as a workaround?

  10. Kashishm273 commented on Apr 7, 2022

    @Kashishm273

    Facing the same issue, any solution to make it work?

  11. One-djey commented on Apr 7, 2022

    @One-djey

    I was stuck with this problem on Android. I haven't found any solution or workaround. Isolate does not work as the main thread since they cannot use MethodChannels (so far it's what I understood).
    My non-productive answer would be: do it in another way.

  12. Kashishm273 commented on Apr 7, 2022

    @Kashishm273

    I ended up using

    import 'dart:io';
    
    // Get the system temp directory.
    var systemTempDir = Directory.systemTemp;
    

    Works fine on different isolate as well. The data that I need to store, is required temporarily and can be exposed publicly.

  13. brunodmn commented on Apr 13, 2022

    @brunodmn

    I ended up using

    import 'dart:io';
    
    // Get the system temp directory.
    var systemTempDir = Directory.systemTemp;
    

    Works fine on different isolate as well. The data that I need to store, is required temporarily and can be exposed publicly.

    Nice workaround for some situations. Unfortunately, won't work if you run a package that uses
    getApplicationDocumentsDirectory() to initialize on isolate, such as hive or shared_preferences.

    What worked for me on Android, but I not tested on iOS yet was related to #360. :

    1. Add packages path_provider_android and path_provider_ios
    2. Add bellow snipet into your isolate (before getApplicationDocumentsDirectory()):
     if (Platform.isAndroid) PathProviderAndroid.registerWith();
     if (Platform.isIOS) PathProviderIOS.registerWith();
    

    Could you give it a try and feedback the results?

  14. stuartmorgan-g commented on Apr 14, 2022

    @stuartmorgan-g
    Contributor

    Closing as the original issue was about a third-party package; when using isolates special handling is required to register plugins, and that's up to the package configuring the isolate to do correctly (or explain how to clients to do correctly if they don't).

    The more recent comments are likely to be #99155 instead; see there for details.

  15. github-actions commented on Apr 28, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  16. locked as resolved and limited conversation to collaborators on Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: crashStack traces logged to the consolep: path_providerPlugin that provides resolved paths to some platform directoriespackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions