yasukotelin / ext_storage

ext_storage is minimal flutter plugin that provides external storage path and external public storage path.
MIT License
29 stars 61 forks source link

MissingPluginException (MissingPluginException(No implementation found for method getExternalStorageDirectory on channel ext_storage)) #2

Closed aidensV closed 3 years ago

aidensV commented 4 years ago

Just Try Simple Code

void _example2() async {
  var path = await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_PICTURES);
  print(path);  // /storage/emulated/0/Pictures
}
PonyPC commented 4 years ago

same

yasukotelin commented 4 years ago

@aidensV @PonyPC Thanks for this issue🧑🏻‍💻 mmm..... Tell me where running on? Android? This plugin is supported for only Android.

limentas commented 4 years ago

I faced the same problem. And I see that when I create my own channel and my android-specific code - I receive this error.

yasukotelin commented 4 years ago

@limentas I don't understand much of it🤔. Can you show me your tried code?

limentas commented 4 years ago

@limentas I don't understand much of itthinking. Can you show me your tried code? I just calling library like this:


Future<void> _saveImage(BuildContext context) async {
try {
final picturesPath = await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_PICTURES);
//...
} catch (err) {
print("Error while saving: $err");
}
}
I'm sorry, I have no time to make simple example and explore it more. You can check full example here: https://gitlab.com/limentas/draw-a-lot/-/tree/3d7e2862ad40284d9500254dccfba18b4e26d018 (link to commit for reproducing error).
The code above located in main_view.dart and you can reproduce error just clicking Save button.
My flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel beta, v1.15.17, on Microsoft Windows [Version 6.3.9600], locale ru-RU) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [√] Chrome - develop for the web [!] Android Studio (version 3.5) X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. [√] Connected device (3 available)

! Doctor found issues in 1 category.

yasukotelin commented 4 years ago

@limentas Thankyou😍!! I tried it on both master branch and 3d7e2862ad40284d9500254dccfba18b4e26d018 commit branch and it worked fine🤔.

I/flutter (30937): Saving picture...
I/flutter (30937): Error during save file: FileSystemException: Creation failed, path = '/storage/emulated/0/Pictures/DrawALot' (OS Error: Permission denied, errno = 13)
I/flutter (30937): Saving complete

I look like to got a path '/storage/emulated/0/Pictures/ .

This run on the Android Emulator "Pixel2".

limentas commented 4 years ago

@yasukotelin I've just checked this commit 3d7e2862ad40284d9500254dccfba18b4e26d018 and found that there is not AndroidManifest for debugging. I've created new brunch 'ReproducingMissingPluginException', checked out it to a new clean folder and got:

I/flutter (32223): Saving picture... I/flutter (32223): Error while saving: MissingPluginException(No implementation found for method getExternalStoragePublicDirectory on channel ext_storage) I/flutter (32223): Saving complete

It's really strangely if it works for you. P.S. master brunch works well because I'm using work around with my own channel and my own implementation of getExternalStoragePublicDirectory.

yasukotelin commented 4 years ago

@limentas I trid your ReproducingMissingPluginException branch and it worked fine on my environment. Can you tell me your environemt? My environment is below.

Development: macOS
Development: Android Studio 3.6
Device: Pixcel2(Android OS10 Emulator), Pixel 3a(Android OS10)

And I crate simple example code.Are you experiencing the same problem? https://github.com/yasukotelin/ext_storage/tree/master/example

PonyPC commented 4 years ago

Update your flutter with new sdk. It seemed that new flutter disallow application access root path in /storage/emulated/0/ If you access DICM directory, you will write your file in path something like /storage/emulated/0/DCIM/data/com.xxx.xxx/files/

yasukotelin commented 4 years ago

@PonyPC uum... I think i'm using a newer version.

Flutter 1.12.13+hotfix.9 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f139b11009 (10 days ago) • 2020-03-30 13:57:30 -0700
Engine • revision af51afceb8
Tools • Dart 2.7.2

But there doesn't appear to be any errors🤔

limentas commented 4 years ago

@yasukotelin I accidentally found solution for my problem. Maybe it will be useful for somebody. My MainActivity.java had no code for registering plugins. Now it looks like this:

@Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    GeneratedPluginRegistrant.registerWith(flutterEngine);
    //...
}

And don't forget import io.flutter.plugins.GeneratedPluginRegistrant; This file (GeneratedPluginRegistrant) generated by flutter engine and it contains all plugins from your yaml file. With this fix your package works well for me. Thank you for your help.

And maybe the following information will be also helpful. I had to implement my own native method to saving pictures, because in Android X API Google deprecated method Environment.getExternalStoragePublicDirectory.

limentas commented 4 years ago

@PonyPC, I think the problem not on flutter side, but in Android SDK level. https://developer.android.com/training/permissions/requesting

PonyPC commented 4 years ago

@limentas My "MainActivity.kt" already has that line. @yasukotelin What's your android SDK version?

yasukotelin commented 4 years ago

@limentas thank you! It's helpful. @PonyPC I've tested on the below

This has never happened in my environment, so I'm at a loss🥺

Does this happen in the example project? https://github.com/yasukotelin/ext_storage/tree/master/example

TugayYaldiz commented 4 years ago

When the first time ext_storage added as a dependency to pubspec.yaml. You can try to stop debugging session and restart it, if it was already running.

ahmadkhedr commented 3 years ago

When the first time ext_storage added as a dependency to pubspec.yaml. You can try to stop debugging session and restart it, if it was already running.

This solved the issue for me....Thank you