Как я сделал репо:
flutter create --androidx -i swift -a kotlin test_firebase_app
- Следуйте инструкциям Flutter Firebase здесь
- Обновите версию kotlin до
1.3.50
in android/build.gradle
buildscript {
ext.kotlin_version = '1.3.50'
// ...
}
- обновление версии gradle до 3.5.0
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
- Добавление библиотек поддержки Android x в
android/app/build.gradle
dependencies {
// ...
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.core:core-ktx:1.1.0"
}
- Применение Google-сервисовподключаемый модуль в конце
android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
- проверьте соединение с базой данных firebase в
main.dart
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)