Repository navigation
Trouble with using path_provider package in an isolate #51685
Description
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+1environment:
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.4dev_dependencies:
flutter_test:
sdk: flutterflutter:
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
VladyslavBondarenko commentedon Mar 17, 2020
Related to #46679
tiagoantunes commentedon Jun 26, 2020
A possible related issue, #59683 (comment).
oligazar commentedon Jan 29, 2021
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?
oligazar commentedon Jan 29, 2021
I manage to work around this issue registering plugins manually in Application.kt
One-djey commentedon Dec 2, 2021
The @oligazar workaround isn't suitable for me and I'm still experiencing the error:
When I call
Directory appDocDir = await getApplicationDocumentsDirectory();from packagepackage:path_provider/path_provider.dartin an Isolate.krunalgajera98 commentedon Feb 7, 2022
Hi, @Drkstr same Issue here, can you please tell me how you solve this error, any help would be appreciated
thanks!
Drkstr commentedon Feb 23, 2022
@krunalgajera98 I never found a workaround for this. I ended up rearchitecting the app to not need isolates.
brunodmn commentedon Mar 4, 2022
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 fetch5 - 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?
Kashishm273 commentedon Apr 7, 2022
Facing the same issue, any solution to make it work?
One-djey commentedon Apr 7, 2022
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.
Kashishm273 commentedon Apr 7, 2022
I ended up using
Works fine on different isolate as well. The data that I need to store, is required temporarily and can be exposed publicly.
brunodmn commentedon Apr 13, 2022
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. :
getApplicationDocumentsDirectory()):Could you give it a try and feedback the results?
stuartmorgan-g commentedon Apr 14, 2022
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.
github-actions commentedon Apr 28, 2022
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 -vand a minimal reproduction of the issue.