Flutter-名称为[DEFAULT]的FirebaseApp不存在

时间:2019-07-25 23:24:23

标签: firebase flutter fingerprint

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

有人建议解决我的问题吗? 谢谢

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

用于初始化FirebaseApp的其他代码似乎已经很老了,我不认为它可以像这里(java.lang.IllegalStateException: FirebaseApp with name [DEFAULT])一样对我有用。

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

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

并进行一些尝试以管理输出。

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)

1 个答案:

答案 0 :(得分: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。祝您好运!