提问人:Dansk 提问时间:10/27/2023 更新时间:10/28/2023 访问量:110
在 Android Studio 中将 Firebase 连接到 Flutter
Connecting Firebase to Flutter in Android Studio
问:
我试图在 firebase 中连接我的 flutter 项目,但我一直收到这个错误
在调试模式下在 sdk gphone x86 上启动 lib\main.dart...
正在运行 Gradle 任务“assembleDebug”...
√ 构建 build\app\outputs\flutter-apk\app-debug.apk。
正在安装 build\app\outputs\flutter-apk\app-debug.apk...
调试服务侦听 ws://127.0.0.1:54542/CBgATS3doF8=/ws
正在将文件同步到设备 sdk gphone x86...
E/flutter (15791):[错误:flutter/runtime/dart_vm_initializer.cc(41)] 未处理的异常:PlatformException(null-error,主机平台返回非 null 返回值的 null 值,null,null)
E/flutter (15791):#0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter (15791):<异步挂起>
E/flutter (15791): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter (15791):<异步挂起>
E/flutter (15791): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter (15791):<异步挂起>
E/flutter (15791): #3 main (package:database/main.dart:5:3)
E/flutter (15791):<异步挂起>
E/颤振 (15791):
我在 youtube 上做了很多教程,但大多数都过时了,大部分语法更改,但即使我找到了更新的教程,情况也总是如此。我按照在 firebase 网站中添加 android 的步骤进行操作
这是我的android\build.gradle
buildscript {
ext.kotlin_version = '1.9.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.0'
}
}
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
}
这是我的 app\build.gradle
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'
}
android {
namespace "com.example.database"
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.database"
// 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 19
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 {
implementation platform('com.google.firebase:firebase-bom:32.4.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.android.support:multidex:1.0.3'
}
答:
我将类路径“com.google.gms:google-services:4.4.0”的版本更改为类路径“com.google.gms:google-services:4.3.15”。它有效,我不知道为什么,但我没有收到错误
评论