在 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):
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
}
生成的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(),
),
],
));
}
到目前为止我做了什么:
我确定它来自GetStorage
。但是,其他人使用 GetStorage
没有问题。想知道为什么它只发生在我的设备上。我还创建了新项目,看看它是否在那里运行。但是,仍然有同样的问题。我测试了新的 Flutter(新鲜)是否适用于 Android。确实可以,但是在添加了这些依赖项之后,它面临着同样的问题。
答案 0 :(得分:2)
在调用插件函数之前请先调用 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)
}
}