在Android Studio中连接Firebase到Flutter

83qze16e  于 2023-11-21  发布在  Android
关注(0)|答案(1)|浏览(101)

我试图在firebase连接我的Flutter项目,但我一直得到这个错误

正在调试模式下在sdk gphone x86上启动lib\main.dart..
正在运行Gradle任务“任务列表".
APK下载器:Build\app\outputs\flutter-apk\app-debug. apk
正在安装build\app\outputs\flutter-apk\app-debug. apk.
在ws://www.example.com上监听服务127.0.0.1:54542/CBgATS3doF8=/ws
同步文件到设备sdk gphone x86.
E/flutter(15791):[ERROR:flutter/runtime/dart_vm_initializer.cc(41)]未处理的异常:PlatformException(null-error,Host platform returned null value for non-null return value.,null,null)
E/flutter(15791):#0 FirebaseCoreHostApi.optionsFromResource(package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/扑动(15791):
E/flutter(15791):#1 MethodsocketelFirebase.initializeApp(package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/扑动(15791):
E/flutter(15791):#2 Firebase.initializeApp(package:firebase_core/src/firebase.dart:43:31)
E/扑动(15791):
E/flutter(15791):#3 main(package:database/main.dart:5:3)
E/扑动(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
}

字符串

这是我的应用\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'

}

nvbavucw

nvbavucw1#

我将类路径'com.google.gms:google-services:4.4.0'的版本更改为类路径'com.google.gms:google-services:4.3.15'。它可以工作,我不知道为什么,但我没有得到错误

相关问题