简体   繁体   中英

Flutter: android MissingPluginException(No implementation found for method getApplicationDocumentsDirectory)

Getting an error on Android Emulator + S10 . iOS devices work perfectly fine.

Error Message:

Note: /Users/gi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_facebook_login-3.0.0/android/src/main/java/com/roughike/facebooklogin/facebooklogin/FacebookLoginPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.                    
Note: /Users/gi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-4.0.2/android/src/main/java/com/jrai/flutter_keyboard_visibility/FlutterKeyboardVisibilityPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.                    
Note: /Users/gi/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-1.0.6/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.                    
Note: Some input files use unchecked or unsafe operations.              
Note: Recompile with -Xlint:unchecked for details.                      
Note: /Users/gi/flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in-4.5.6/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        22.5s
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...                 7.9s

E/flutter ( 5394): [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 ( 5394): #0      GetStorage._init (package:get_storage/src/storage_impl.dart:50:7)
E/flutter ( 5394): <asynchronous suspension>
E/flutter ( 5394): #1      new GetStorage._internal.<anonymous closure> (package:get_storage/src/storage_impl.dart:28:7)
E/flutter ( 5394): <asynchronous suspension>
E/flutter ( 5394): #2      main (package:flutter/main.dart:32:3)
E/flutter ( 5394): <asynchronous suspension>
E/flutter ( 5394): 

app build.gradle

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.first.flutter"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

android build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

GeneratedPluginRegistrant.java

package io.flutter.plugins;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;

/**
 * Generated file. Do not edit.
 * This file is generated by the Flutter tool based on the
 * plugins that support the Android platform.
 */
@Keep
public final class GeneratedPluginRegistrant {
  public static void registerWith(@NonNull FlutterEngine flutterEngine) {
    ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
    flutterEngine.getPlugins().add(new io.flutter.plugins.connectivity.ConnectivityPlugin());
      com.roughike.facebooklogin.facebooklogin.FacebookLoginPlugin.registerWith(shimPluginRegistry.registrarFor("com.roughike.facebooklogin.facebooklogin.FacebookLoginPlugin"));
    flutterEngine.getPlugins().add(new com.jrai.flutter_keyboard_visibility.FlutterKeyboardVisibilityPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin());
    flutterEngine.getPlugins().add(new com.baseflow.geolocator.GeolocatorPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.googlemaps.GoogleMapsPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.googlesignin.GoogleSignInPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.imagepicker.ImagePickerPlugin());
    flutterEngine.getPlugins().add(new dev.flutter.plugins.integration_test.IntegrationTestPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
    flutterEngine.getPlugins().add(new com.aboutyou.dart_packages.sign_in_with_apple.SignInWithApplePlugin());
    flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.urllauncher.UrlLauncherPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.videoplayer.VideoPlayerPlugin());
  }
}

MainActivity.kt

package com.example.sp

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

pubspec.yaml:

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  get: ^3.22.2
  custom_splash: ^0.0.2
  http: ^0.12.2
  google_fonts: ^1.1.1
  flutter_slidable: ^0.5.7
  get_storage: ^1.4.0
  # background_fetch: ^0.6.0
  video_player: ^1.0.1
  modal_bottom_sheet: ^1.0.0+1
  socket_io_client: ^0.9.12
  google_sign_in: ^4.5.6
  url_launcher: ^5.7.10
  animations: ^1.1.2
  sign_in_with_apple: ^2.5.4
  connectivity: ^2.0.2
  image_picker: ^0.6.7+14
  google_maps_flutter: ^1.0.6
  path_provider: ^1.6.24
  splash_screen_view: ^1.0.3
  flutter_facebook_login: ^3.0.0
  fab_circular_menu: ^1.0.0
  liquid_pull_to_refresh: ^2.0.0
  font_awesome_flutter: ^8.10.1
  cached_network_image: ^2.4.1
  geolocator: ^6.1.13
  json_annotation: ^3.1.1
  json_serializable: ^3.5.1
  responsive_framework: ^0.0.14
  flutter_typeahead: ^1.9.1
  direct_select_flutter: ^1.0.7
  flutter_keyboard_visibility: ^4.0.0
  random_string: ^2.1.0

main.dart file

void main() async {
  await GetStorage.init();


  if (GetStorage().read('hi') == null) {
   print('heeellooo');
  } else {
   print('goodbyeeee');
  }


  runApp(GetMaterialApp(
    home: SplashScreenView(
      home: App(),
      duration: 3000,
      imageSize: 200,
      imageSrc: "assets/images/splash.png",
      backgroundColor: Colors.black,
    ),
    getPages: [
      GetPage(
        name: '/home',
        page: () => Home(),
      ),
    
    ],
  ));
}

What I have done so far:

  • flutter clean & run
  • rebuilding pub-cache
  • delete path_provider and reinstall path_provider with pub get and stuffs
  • remove await GetStorage.init(); <--- this work
  • call GetStorage.init(); in different places

I am sure it is from GetStorage . However, others use the GetStorage without a problem. Wondering why it is happening just on my device. I also created the new project and see if it runs there. But, still has the same problem. I tested if the new Flutter (fresh) works on Android. It does, but then after adding these dependencies, it faces the same problem.

Please call WidgetsFlutterBinding.ensureInitialized(); before calling plugin functions.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await GetStorage.init();
  ...
}

Also, modify your MainActivity to...

import android.os.Bundle
import com.facebook.FacebookSdk
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        FacebookSdk.sdkInitialize(applicationContext)
        super.onCreate(savedInstanceState)
    }

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM