簡體   English   中英

Flutter: android MissingPluginException(找不到方法 getApplicationDocumentsDirectory 的實現)

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

在 Android Emulator + S10 上出現錯誤 iOS 設備工作正常。

錯誤信息:

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

應用程序 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
}

生成的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

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文件

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(),
      ),
    
    ],
  ));
}

到目前為止我做了什么:

  • flutter 清潔運行
  • 重建 pub-cache
  • 刪除 path_provider 並使用 pub get 和 stuffs 重新安裝 path_provider
  • 刪除等待 GetStorage.init(); <---這個作品
  • 調用 GetStorage.init(); 在不同的地方

我確定它來自GetStorage 但是,其他人使用GetStorage沒有問題。 想知道為什么它只發生在我的設備上。 我還創建了新項目,看看它是否在那里運行。 但是,仍然有同樣的問題。 我測試了新的 Flutter(新鮮)是否適用於 Android。 確實如此,但是在添加了這些依賴項之后,它面臨着同樣的問題。

請調用WidgetsFlutterBinding.ensureInitialized(); 在調用插件函數之前。

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

另外,將您的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM