简体   繁体   English

我正在使用 flutter 编写 Firebase 应用程序,但我收到有关 google-services.json 和初始化的错误

[英]I am coding a Firebase app with flutter but i am getting errors about google-services.json and inititilization

I am coding a sign up screen in flutter and i am using Firebase for it but i am gettin this error.But in my project i have google-services.json in android\app.我正在 flutter 中编写注册屏幕,我正在使用 Firebase 但我遇到了这个错误。但在我的项目中,我在 android\app 中有 google-services.json。 I can not understand why can you help me?我不明白你为什么能帮助我? I did the initilization and the things from firebase' s site我在 firebase 的网站上进行了初始化和操作

E/flutter (26694): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. E/flutter (26694): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] 未处理的异常:[core/not-initialized] Firebase 尚未正确初始化。 Have you added the "google-services.json" file to the project?您是否将“google-services.json”文件添加到项目中?

main.dart main.dart

import 'package:edebiyat_uygulamasi/giris.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(App());
}

class App extends StatelessWidget {
  // Create the initialization Future outside of `build`:

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // Initialize FlutterFire:
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          debugPrint("something went wrong");
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return MaterialApp(
            debugShowCheckedModeBanner: false,
            theme:
                ThemeData(primaryColor: Colors.white, errorColor: Colors.white),
            home: Scaffold(
              resizeToAvoidBottomInset: false,
              backgroundColor: Colors.purple,
              appBar: AppBar(
                title: Text("Engelsiz Edebiyat"),
              ),
              body: GirisSayfasi(),
            ),
          );
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return CircularProgressIndicator();
      },
    );
  }
}

sign up screen注册屏幕

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';


FirebaseAuth _auth = FirebaseAuth.instance;

String _Email, _Sifre;

class GirisSayfasi extends StatefulWidget {
  @override
  _GirisSayfasiState createState() => _GirisSayfasiState();
}

class _GirisSayfasiState extends State<GirisSayfasi> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Container(
            child: Text(
              "E-posta",
              style: TextStyle(fontSize: 22, color: Colors.white),
            ),
            margin: EdgeInsets.only(top: 30, left: 30),
            alignment: Alignment.topLeft,
          ),
          Container(
            child: TextField(
              decoration: InputDecoration(
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(10.0)),
                  borderSide: BorderSide(color: Colors.white),
                ),
                hintText: "Emailinizi Giriniz",
                hintStyle: TextStyle(color: Colors.white),
              ),
              onChanged: (String edeger) => _Email = edeger,
            ),
            padding: EdgeInsets.only(left: 35, right: 35),
          ),
          Container(
            child: Text(
              "Şifre",
              style: TextStyle(fontSize: 22, color: Colors.white),
            ),
            margin: EdgeInsets.only(top: 30, left: 30),
            alignment: Alignment.topLeft,
          ),
          Container(
            child: TextField(
              decoration: InputDecoration(
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(10.0)),
                  borderSide: BorderSide(color: Colors.white),
                ),
                hintText: " Şifrenizi Giriniz",
                hintStyle: TextStyle(color: Colors.white),
              ),
              onChanged: (String sdeger) => _Sifre = sdeger,
            ),
            padding: EdgeInsets.only(left: 35, right: 35),
          ),
          Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Container(
                child: RaisedButton(
                    onPressed: HesapOlustur,
                    child: Text("Hesap Oluştur"),
                    color: Colors.white),
                alignment: Alignment.center,
              ),
            ],
          ),
        ],
      ),
    );
  }
}

HesapOlustur() async {
  UserCredential _credential = await _auth.createUserWithEmailAndPassword(
      email: _Email, password: _Sifre);
}

pubspec.yaml pubspec.yaml

name: edebiyat_uygulamasi
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  firebase_auth: ^0.18.1+2
  firebase_core: ^0.5.0+1

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter
  
  # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

android\buildgradle安卓\buildgradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

android\app\buildgradle android\app\buildgradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}


apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"


android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.edebiyat_uygulamasi"
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
}

In your android/app/build.gradle put the below code I have added this line apply plugin: 'com.google.gms.google-services'在您的android/app/build.gradle中放入以下代码,我添加了这一行apply plugin: 'com.google.gms.google-services'

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}


apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"


android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.edebiyat_uygulamasi"
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

See if it works.看看它是否有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该编辑google-services.json文件吗? - Am I supposed to edit the google-services.json file? 添加google-services.json后,我也收到类似的错误 - after adding google-services.json also i am getting error like 我在哪里放置 Googleservices.json 在 Flutter 应用程序中以解决“google-services.json 丢失”的问题 - Where do I place Googleservices.json in Flutter app in order to solve 'google-services.json is missing' 我可以在不使用google-services.json的情况下初始化Firebase吗? - Can I initialize Firebase without using google-services.json? 适用于Firebase和Google Analytics(分析)的google-services.json - google-services.json for Firebase and Google Analytics 我是否需要将单独的google-services.json用于Firebase和Google API - Do I need separate google-services.json for firebase and Google APIs 在我将原来的google-services.json替换为与Firebase相关的google-services.json后,Google登录停止了工作 - Google sign-in stopped working after I replaced the original google-services.json with one pertaining to Firebase Android Studio - 如何从谷歌服务获取 Firebase URL。 因为当我打开 google-services.json 时,没有 firebase URL 的代码 - Android Studio - How to get Firebase URL from google-services.json? Cause when I open the google-services.json, there's no code for firebase URL 具有多个项目的 Firebase google-services.json? - Firebase google-services.json with multiple projects? Firebase:google-services.json 错误 - Firebase: google-services.json error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM