jonataslaw / get_storage

A fast, extra light and synchronous key-value storage to Get framework
MIT License
343 stars 81 forks source link

GetStorage init() failed on Android #35

Open Ketlark opened 3 years ago

Ketlark commented 3 years ago

Hi, i used lib on iOS and i just test my app on a Pixel 3a under AndroidAPI 27 and got this error when i tried to init storage

E/flutter ( 6985): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider) E/flutter ( 6985): #0 GetStorage._init (package:get_storage/src/storage_impl.dart:47:7) E/flutter ( 6985): <asynchronous suspension> E/flutter ( 6985): #1 new GetStorage._internal.<anonymous closure> (package:get_storage/src/storage_impl.dart:27:13) E/flutter ( 6985): #2 new Future.<anonymous closure> (dart:async/future.dart:175:37) E/flutter ( 6985): #3 _rootRun (dart:async/zone.dart:1182:47) E/flutter ( 6985): #4 _CustomZone.run (dart:async/zone.dart:1093:19) E/flutter ( 6985): #5 _CustomZone.runGuarded (dart:async/zone.dart:997:7) E/flutter ( 6985): #6 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23) E/flutter ( 6985): #7 _rootRun (dart:async/zone.dart:1190:13) E/flutter ( 6985): #8 _CustomZone.run (dart:async/zone.dart:1093:19) E/flutter ( 6985): #9 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23) E/flutter ( 6985): #10 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15) E/flutter ( 6985): #11 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19) E/flutter ( 6985): #12 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5) E/flutter ( 6985): #13 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Any ideas ? Here my code :

    import 'package:Witook/app/routes/app_pages.dart';
  import 'package:Witook/app/services/oauth_handler.dart';
  import 'package:Witook/app/services/uri_handler.dart';
  import 'package:flutter/material.dart';
  import 'package:get/get.dart';
  import 'package:get_storage/get_storage.dart';

  import 'app/routes/app_routes.dart';
  port 'app/translations/app_translations.dart';

    Future<void> main() async {
      initServices();
      runApp(MyApp());
    }

    void initServices() async {
      print('starting services ...');

      await GetStorage.init(); ----------------> PROBLEM HERE
      await Get.putAsync(() => UriHelper().init(), tag: 'uri_handler');
      Get.put(OauthHandler(), tag: 'oauth_handler');

      //TODO REMOVE FOR PROD
      await GetStorage().remove('auth_token');

      /// Here is where you put get_storage, hive, shared_pref initialization.
      /// or moor connection, or whatever that's async.
      //await Get.putAsync(() => DBService.init());
      //await Get.putAsync(SettingsService()).init();

      print('All services started...');
    }

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        var storage = GetStorage();

        return GetMaterialApp(
            debugShowCheckedModeBanner: false,
            theme: null,
            locale: Locale('fr', 'FR'),
            getPages: AppPages(storage).getPages(),
            defaultTransition: Transition.fade,
            initialRoute:
                storage.hasData('launched') ? Routes.HOME : Routes.ONBOARDING,
            translationsKeys: AppTranslation.translations);
      }
    }
jonataslaw commented 3 years ago

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

You need a pub packages get before a build.

Ketlark commented 3 years ago

Already did 'pub get' before, it works fine on iOS and i have the lib on my build folder. But error is still here

omaralmgerbie commented 3 years ago

any news about the error?

Ketlark commented 3 years ago

still waiting for a solution

jonataslaw commented 3 years ago

Add to pubspec:

path_provider:

give pub get

give other pub get

remove path_provider from your pubspec

build the project again.

path_provider is a flutter depedency, but I saw in a recent issue about it in the Flutter repository recently, that sometimes the package doesn't go into the cache, or it goes into an empty folder, and doing that resolves, most of the time. Try this and see if it works for you.

Note: any storage plugin uses path_provider. Both GetStorage, SharedPreferences, and Hive, as any database will use this dependency, and unfortunately it is problematic, but there is no possibility of not using it.

omaralmgerbie commented 3 years ago

i just did exactly as you suggested but im still having the same error

qbait commented 3 years ago

I have the same error, but only for app-release.apk when running flutter build apk. I've tried different versions of Flutter and I've added explicitly path_provider: ^1.6.24 to pubspec. Still no luck. Any idea, how to solve it?

qbait commented 3 years ago

Any update on that one? Still having a problem when releasing the version with flutter build apk. Debug version of the app work alright. I've tried to clear cache and refresh path_provider in pubspec as @jonataslaw suggested. Still no luck.

ravindravala commented 3 years ago

same error as @qbait , Please give any solution

ravindravala commented 3 years ago

Don't know why but error gone when i removed image_picker: plugin from App , try to do this solution if possible .

qbait commented 3 years ago

@ravindravala thanks for the info. However, I'm not using image_picker in my project.

qbait commented 3 years ago

The fix on my side was to change the build tools version in build.gradle It works with classpath 'com.android.tools.build:gradle:3.5.0'

prateekmedia commented 3 years ago

Just rebuild the app, that fixed my issue. or try running flutter clean first and then rebuild the app.

Ketlark commented 3 years ago

Just rebuild the app, that fixed my issue. or try running flutter clean first and then rebuild the app.

Read the entire thread, we've already try this solution

prateekmedia commented 3 years ago

Just rebuild the app, that fixed my issue. or try running flutter clean first and then rebuild the app.

Read the entire thread, we've already try this solution

Ok, it was the solution for me, looks like you have another issue related to this error.

jonataslaw commented 3 years ago

1- This is a totally random error. 2- This problem occurs with the official Flutter path_provider plugin. It's not a problem with Get Storage, but it affects us, as it affects all other plugins. 3- The problem is with the registration of the plugin in your project, adding the package to be cached, updating the flutter, and updating the project sdk, can help. 4- It is impossible for us to create any solution for this, the Flutter Team that needs to solve it. And all the main official plugins use it (plugins, not packages). We can quote: google_fonts, camera, firebase_ml_vision, audioplayers, graphql_flutter, hive_flutter, localstorage, shared_preferences, and all other plugins that use storage. We cannot manage the storage alone, so we depend on an official dart plugin for this, and this dart plugin is giving you this problem, which can be caused by a multitude of reasons, and any other plugin you use will be the same.

This error must have some behavior in common, since it never happened to me, and 99% of users who complain about it in community chats, return 3 minutes later with "resolved with flutter clean". So I really need a reproduction code to investigate this, a project where it occurs, because it’s not saying, "I did it and it didn’t solve it" that we will be able to find out where this happened to report to the Flutter team.

Manjunath-VM commented 3 years ago

Facing same issue can any one help me on this .

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

Manjunath-VM commented 3 years ago

class LocalStorage{ var box; LocalStorage(){

 initLocalStorage();
 box = GetStorage();

}

void initLocalStorage() async{ await GetStorage.init();<--- Here i am getting the issue }

void saveStringToStorage(String key,String value){ box.write(key, value); } void saveIntToStorage(String key,int value){ box.write(key, value); } String getStringFromStorage(String key){ return box.read(key).toString(); } int getIntFromStorage(String key){ return box.read(key); } void clearStorage(){ box.erase(); }

}

prateekmedia commented 3 years ago

await GetStorage.init();<--- Here i am getting the issue

As I know you have to only init it once in the main method as mentioned in readme I think so

Manjunath-VM commented 3 years ago

@prateekmedia Actually getting this exception E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)

0 GetStorage._init (package:get_storage/src/storage_impl.dart:50)

1 new GetStorage._internal. (package:get_storage/src/storage_impl.dart:28)

2 LocalStorage.initLocalStorage (package:medeva/utility/local_storage.dart:15)

LUK3D commented 3 years ago

same error here.

E/flutter (29335): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider) E/flutter (29335): #0 GetStorage._init (package:get_storage/src/storage_impl.dart:50) E/flutter (29335): E/flutter (29335): #1 new GetStorage._internal. (package:get_storage/src/storage_impl.dart:28) E/flutter (29335): E/flutter (29335): #2 main (package:eventus/main.dart:40) E/flutter (29335): E/flutter (29335):

MohamedSaad8 commented 3 years ago

Don't know why but error gone when i removed image_picker: plugin from App , try to do this solution if possible .

thats is true , but how i can use the image picker with it ?

Hiomma commented 3 years ago

The fix on my side was to change the build tools version in build.gradle It works with classpath 'com.android.tools.build:gradle:3.5.0'

Hey everyone, this solution works for me! I had a problem with GetStorage and I just changed the Gradles' version into android/build.gradle

cairuoyu commented 3 years ago

Channel stable, 2.0.2 is ok

dansuzzio commented 3 years ago

E/flutter (17589): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider) E/flutter (17589): #0 GetStorage._init (package:get_storage/src/storage_impl.dart:50) E/flutter (17589): E/flutter (17589): #1 new GetStorage._internal. (package:get_storage/src/storage_impl.dart:28) E/flutter (17589): E/flutter (17589): #2 main (package:indiebridge_app/main.dart:14) E/flutter (17589): E/flutter (17589):

This was the error I had while trying to run GetStorage.init() on an Android device in release mode, which made the app freeze with a white screen.

Relevant versions (no path_provider in pubscpec.yaml):

I found 2 different solutions that got rid of the error:

  1. Upgraded all packages to their latest versions, which meant migrating to null-safety. Or
  2. Downgraded gradle in android/build.gradle to:
    • classpath 'com.android.tools.build:gradle:3.6.4'.
sheheryarkhan501 commented 3 years ago

happened with me when I was adding mediation, so probably some problem with mediation setup, so when removed everything is working fine. So, all that is needed to be done is to take every step carefully when you add a new thing.

mohadel92 commented 2 years ago

Guys after 3 days debugging this issue , i found that using flutter_facebook_auth was the problem even after replacing shared_preferences i am still getting the same error , removing flutter facebook login was the cure @jonataslaw was right about that this issue is not related to get_storage

mohadel92 commented 2 years ago

As a definitive solution for this issue implementing the required part in the Android version of the flutter_facebook_auth was the cure

shmehdi01 commented 2 years ago

I'm having same issue, still not resolved

Obada2020 commented 1 year ago

I'm having same issue, still not resolved after tried all solutions I moved to shared prefrences 😓

FujiwaraChoki commented 2 days ago

+1