Flutter-名称为[DEFAULT]的FirebaseApp不存在 [英] Flutter - FirebaseApp with name [DEFAULT] doesn't exist
问题描述
我正在使用Firebase身份验证系统和Firestore开发Flutter应用程序.我工作了3个月,之前没有遇到此错误.现在,我在Play商店上发布了我的应用程序,并且在模拟器的调试版本中也发现了此错误.我认为已经正确配置了系统,因为firebase工作了一段时间. 我认为在flutter升级后,我构建的所有apk都会发生此错误.
I'm working on a flutter application using firebase authentication system and Firestore. I worked for 3 months and I didn't encounter this error before. Now I published my application on play store and I found this error also for debug version with the emulator. I think to have configured properly the system because firebase worked for a while. I think that this error occurs for all the apk that I builded after the upgrade of flutter.
有人建议解决我的问题吗? 谢谢
Some suggestion to solve my problem? Thanks
我在firebase上输入我的捆绑包ID,然后下载google-service.json文件,复制并粘贴到android/app文件夹并进行构建.我还尝试清洁(如此处所述 https://github.com/flutter/flutter/issues /28003 )并构建项目,然后输入一些SHA1和SHA-256指纹,以尝试是否是此问题,但我不确定在firebase上输入哪个SHA1.重新下载google-service.json并清理-构建项目.
I enter my bundle ID on firebase and download the google-service.json file, copy and paste on android/app folder and build. I also tried to clean (as mentioned here https://github.com/flutter/flutter/issues/28003 ) and build the project and to enter some SHA1 and SHA-256 fingerprints to try if it was this the problem but I'm not sure which SHA1 enter on firebase. ReDownloaded the google-service.json and clean - build the project.
用于初始化FirebaseApp的其他代码似乎已经很老了,我不认为它可以像下面这样对我有用(
Other codes to initialise the FirebaseApp seems pretty old and I don't think that it can work for me like here (java.lang.IllegalStateException: FirebaseApp with name [DEFAULT]) .
我只是使用此代码对用户进行身份验证
I just authenticate a user using this code
user = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: _email, password: _password);
并尝试尝试捕获以管理输出.
and do some try catch to manage the output.
android/build.gradle
android/build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android/app/build.gradle
android/app/build.gradle
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.luxywebdesign.pocketstcw"
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
signingConfigs {
release {
storeFile file("my-release-key.keystore")
storePassword "StorePassword"
keyAlias "KeyAlias"
keyPassword "Password"
}
}
buildTypes {
release {
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
pubspec.yaml
pubspec.yaml
environment:
sdk: ">=2.1.0 <3.0.0"
firebase_storage:
dependencies:
flutter:
sdk: flutter
firebase_auth: 0.8.2
file_picker: ^1.3.3
firebase_storage: ^2.1.0+1
firebase_core: 0.3.1+1
cloud_firestore: ^0.9.7
permission_handler: ^2.2.0
path_provider: ^0.5.0+1
http: ^0.12.0+1
url_launcher: ^5.0.2
open_file: ^2.0.1+2
datetime_picker_formfield: ^0.1.8
share:
git:
url: https://github.com/d-silveira/flutter-share.git
flutter_launcher_icons: ^0.7.0
image_picker: ^0.6.0+1
modal_progress_hud: ^0.1.3
flutter_keychain: ^1.0.0
pdf: ^1.3.7
image: ^2.0.7
flutter_local_notifications: ^0.6.1
auto_size_text: ^2.0.1
shared_preferences: ^0.5.3+1
错误消息:
D/FirebaseApp(23461): Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
在安装apk和...后开始...
at the start after the installation of the apk and ...
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.1.0:280)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.getAuth(FirebaseAuthPlugin.java:76)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.onMethodCall(FirebaseAuthPlugin.java:108)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
推荐答案
我认为问题是您没有正确配置配置.确保遵循以下步骤:
I think the problem is you didn't make right the configuration settings. make sure to follow these steps :
-
添加您的google-service.json文件
Add your google-service.json file
添加apply plugin: 'com.google.gms.google-services'
(应用级等级)
添加apply plugin: 'com.android.application'
(应用级等级)
添加classpath 'com.google.gms:google-services:4.3.3'
(项目级gradle)
Add classpath 'com.google.gms:google-services:4.3.3'
(project-level gradle)
完成所有这些步骤后,您的问题应该得到解决.一次我也遇到了同样的问题,然后我才意识到我没有添加步骤2.祝您好运!
After all this steps your problem should be solved. I also had the same problem once then I realise I didn't add step 2. Good Luck!
这篇关于Flutter-名称为[DEFAULT]的FirebaseApp不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!