Flutter集成Firebase登录注册时遇PlatformException初始化错误求助
Flutter Firebase初始化报错:PlatformException(null-error)
运行基于Flutter的Firebase注册登录应用时,触发如下异常:PlatformException(null-error, Host platform returned null value for non-null return value., null, null)
错误栈信息:
E/flutter ( 6840): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7) E/flutter ( 6840): <asynchronous suspension> E/flutter ( 6840): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25) E/flutter ( 6840): <asynchronous suspension> E/flutter ( 6840): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31) E/flutter ( 6840): <asynchronous suspension> E/flutter ( 6840): #3 main (package:firebaseapp/main.dart:6:3) E/flutter ( 6840): <asynchronous suspension> E/flutter ( 6840):
配置文件信息
1. build.gradle(app)
plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" id("com.google.gms.google-services") } def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: 'com.google.gms.google-services' android { namespace "com.example.firebaseapp" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } 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.example.firebaseapp" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion 22 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName multiDexEnabled true } 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 } } } flutter { source '../..' } dependencies {}
2. build.gradle(android)
buildscript { ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.13' } } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } tasks.register("clean", Delete) { delete rootProject.buildDir }
3. main.dart代码
void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(const MyApp()); }
pubspec.yaml配置

已尝试StackOverflow上所有相关解决方案,问题仍未解决,寻求帮助。
内容的提问来源于stack exchange,提问作者K.D.Dilshan
相关产品推荐
相关产品推荐

