简体   繁体   English

Flutter: android MissingPluginException(找不到方法 getApplicationDocumentsDirectory 的实现)

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

Getting an error on Android Emulator + S10 .在 Android Emulator + S10 上出现错误 iOS devices work perfectly fine. iOS 设备工作正常。

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应用程序 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 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生成的PluginRegistrant.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 MainActivity.kt

package com.example.sp

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

pubspec.yaml: 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 main.dart文件

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 flutter 清洁运行
  • rebuilding pub-cache重建 pub-cache
  • delete path_provider and reinstall path_provider with pub get and stuffs删除 path_provider 并使用 pub get 和 stuffs 重新安装 path_provider
  • remove await GetStorage.init();删除等待 GetStorage.init(); <--- this work <---这个作品
  • call GetStorage.init();调用 GetStorage.init(); in different places在不同的地方

I am sure it is from GetStorage .我确定它来自GetStorage However, others use the GetStorage without a problem.但是,其他人使用GetStorage没有问题。 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.我测试了新的 Flutter(新鲜)是否适用于 Android。 It does, but then after adding these dependencies, it faces the same problem.确实如此,但是在添加了这些依赖项之后,它面临着同样的问题。

Please call WidgetsFlutterBinding.ensureInitialized();请调用WidgetsFlutterBinding.ensureInitialized(); before calling plugin functions.在调用插件函数之前。

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

Also, modify your MainActivity to...另外,将您的MainActivity修改为...

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)
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MissingPluginException(在通道 plugins.flutter.io/path_provider 上找不到方法 getApplicationDocumentsDirectory 的实现) - MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider) 基于 Flutter 的 Android 应用程序抛出 MissingPluginException(未找到通道上的方法的实现) - Flutter based Android app throwing MissingPluginException(No implementation found for method on channel) MissingPluginException(在通道 flutter 上未找到方法 requestPermissions 的实现 - MissingPluginException(No implementation found for method requestPermissions on channel flutter MissingPluginException(在 Android 上找不到方法 Firebase#initializeCore 在通道插件上的实现。flutter.io/firebase_core) - MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) on Android MissingPluginException(在通道 flutter_inapp 上找不到方法 initConnection 的实现) - MissingPluginException(No implementation found for method initConnection on channel flutter_inapp) Flutter:在通道插件上找不到方法 getApplicationDocumentsDirectory 的实现。flutter.io/path_provider - Flutter: No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider Flutter:未处理的异常:MissingPluginException(在通道上找不到方法的实现) - Flutter: Unhandled Exception: MissingPluginException(No implementation found for method on channel) MissingPluginException(MissingPluginException(在通道 plugins.flutter.io/firebase_core 上找不到方法 Firebase#initializeCore 的实现) - MissingPluginException (MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) Flutter MissingPluginException(在通道 flutter.baseflow.com/permissions/methods 上找不到方法 init 的实现) - Flutter MissingPluginException(No implementation found for method init on channel flutter.baseflow.com/permissions/methods) MissingPluginException(在通道 app.meedu/flutter_facebook_auth 上找不到方法登录的实现):Flutter - MissingPluginException(No implementation found for method login on channel app.meedu/flutter_facebook_auth): Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM