【问题标题】:Flutter - FirebaseApp with name [DEFAULT] doesn't existFlutter - 名称为 [DEFAULT] 的 FirebaseApp 不存在
【发布时间】:2019-12-04 06:44:50
【问题描述】:

我正在开发一个使用 firebase 身份验证系统和 Firestore 的颤振应用程序。我工作了3个月,之前没有遇到过这个错误。现在我在 Play Store 上发布了我的应用程序,我发现这个错误也适用于使用模拟器的调试版本。我认为已经正确配置了系统,因为 firebase 工作了一段时间。 我认为我在flutter升级后构建的所有apk都会出现这个错误。

有什么建议可以解决我的问题吗? 谢谢

我在 firebase 上输入我的包 ID 并下载 google-service.json 文件,复制并粘贴到 android/app 文件夹并构建。我还尝试清理(如这里提到的 https://github.com/flutter/flutter/issues/28003 )并构建项目并输入一些 SHA1 和 SHA-256 指纹以尝试是否是这个问题,但我不确定哪个 SHA1 进入 firebase。重新下载 google-service.json 并清理 - 构建项目。

初始化 FirebaseApp 的其他代码似乎很老了,我认为它不能像这里那样为我工作 (java.lang.IllegalStateException: FirebaseApp with name [DEFAULT])。

我只是使用此代码对用户进行身份验证

      user = await FirebaseAuth.instance
          .signInWithEmailAndPassword(email: _email, password: _password);

然后做一些 try catch 来管理输出。

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 {
    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

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后开始...

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)

【问题讨论】:

  • 您找到解决方案了吗?

标签: firebase flutter fingerprint


【解决方案1】:

我认为问题在于您没有正确设置配置。请务必按照以下步骤操作:

  1. 添加您的 google-service.json 文件

  2. 添加apply plugin: 'com.google.gms.google-services'(应用级等级)

  3. 添加apply plugin: 'com.android.application'(应用级等级)

  4. 添加classpath 'com.google.gms:google-services:4.3.3'(项目级gradle)

完成所有这些步骤后,您的问题应该得到解决。我也有同样的问题,然后我意识到我没有添加第 2 步。祝你好运!

【讨论】:

    猜你喜欢
    • 2019-07-09
    • 2016-09-17
    • 2016-12-07
    • 2021-10-17
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    相关资源
    最近更新 更多