Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
名称为DEFAULT的Flatter Firebase实时数据库FirebaseApp不';不存在。可用应用程序名称:[默认值]_Firebase_Kotlin_Firebase Realtime Database_Flutter_Androidx - Fatal编程技术网

名称为DEFAULT的Flatter Firebase实时数据库FirebaseApp不';不存在。可用应用程序名称:[默认值]

名称为DEFAULT的Flatter Firebase实时数据库FirebaseApp不';不存在。可用应用程序名称:[默认值],firebase,kotlin,firebase-realtime-database,flutter,androidx,Firebase,Kotlin,Firebase Realtime Database,Flutter,Androidx,我是如何进行回购的: flatter create--androidx-i swift-a kotlin测试\u firebase\u应用程序 遵循Flatter Firebase的说明 在android/build.gradle中将kotlin版本升级到1.3.50 将gradle版本升级到3.5.0 升级gradle包装器distributionUrl 在android/app/build.gradle中添加android x支持库 在android/app/build.g

我是如何进行回购的:

  • flatter create--androidx-i swift-a kotlin测试\u firebase\u应用程序
  • 遵循Flatter Firebase的说明
  • android/build.gradle中将kotlin版本升级到
    1.3.50
  • 将gradle版本升级到3.5.0
  • 升级gradle包装器distributionUrl
  • 在android/app/build.gradle中添加android x支持库
  • 在android/app/build.gradle的末尾应用google服务插件
  • main.dart

void main(){
final firebaseApp=firebaseApp(名称:“默认”);
final db=FirebaseDatabase(
应用程序:firebaseApp
).reference();
打印('检查数据库连接!');
db.child('rooms').once()。然后((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(名称:“默认”);
对此

final firebaseApp=firebaseApp(名称:“[默认]”);

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


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


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


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

[        ] 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)