gpt4 book ai didi

firebase - 名称为 DEFAULT 的 Flutter Firebase 实时数据库 FirebaseApp 不存在。可用的应用程序名称 : [DEFAULT]

转载 作者:行者123 更新时间:2023-12-02 13:34:53 24 4
gpt4 key购买 nike

我是如何进行 repo 的:

  • flutter create --androidx -i swift -a kotlin test_firebase_app
  • 遵循 Flutter Firebase 说明 here
  • 将 kotlin 版本升级到 1.3.50android/build.gradle

  • buildscript {
    ext.kotlin_version = '1.3.50'
    // ...
    }

  • 升级 gradle 版本到 3.5.0

  • dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
    }

  • 升级 gradle 包装器 distributionUrl to support the gradle version

  • distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

  • android/app/build.gradle 中添加 android x 支持库

  • dependencies {
    // ...
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation "androidx.core:core-ktx:1.1.0"
    }

  • android/app/build.gradle 末尾应用 google-services 插件

  • apply plugin: 'com.google.gms.google-services'

  • 检查 main.dart 中的 firebase 数据库连接


  • void main() {
    final firebaseApp = FirebaseApp(name: 'DEFAULT');
    final db = FirebaseDatabase(
    app: firebaseApp
    ).reference();
    print('checking db connection!');
    db.child('rooms').once().then((result) => print('result = $result'));

    runApp(MyApp());
    }


    得到错误:
    [        ] I/flutter (20246): checking db connection!
    [ +38 ms] E/MethodChannel#plugins.flutter.io/firebase_database(20246): Failed to handle method call
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): java.lang.IllegalStateException: FirebaseApp with name DEFAULT doesn't exist. Available app names: [DEFAULT]
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@17.0.0:269)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin.onMethodCall(FirebaseDatabasePlugin.java:241)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at android.os.MessageQueue.nativePollOnce(Native Method)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at android.os.MessageQueue.next(MessageQueue.java:326)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at android.os.Looper.loop(Looper.java:160)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at android.app.ActivityThread.main(ActivityThread.java:6669)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at java.lang.reflect.Method.invoke(Native Method)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    [ ] E/MethodChannel#plugins.flutter.io/firebase_database(20246): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

    最佳答案

    我终于找到了解决方案

    改变这个

        final firebaseApp = FirebaseApp(name: 'DEFAULT');

    对此

        final firebaseApp = FirebaseApp(name: '[DEFAULT]');

    😞

    关于firebase - 名称为 DEFAULT 的 Flutter Firebase 实时数据库 FirebaseApp 不存在。可用的应用程序名称 : [DEFAULT],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58528230/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com