简体   繁体   中英

flutter) There's a problem using firebase

I'm going to develop apps and webs using firebase. However, if I add firebase and try to use it, an error is output.

Below is the addition and test of Android firebase in the new project.

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  firebase_core: ^1.6.0
  #  firebase_auth: ^3.1.1

I put the google-services.json in the Android-app folder. android-build.gradle

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

app-build.gradle

apply plugin: 'com.google.gms.google-services' //bottom

And main.dart

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

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

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text("12345"),
        ),
      ),
    );
  }
}

It's error

    Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.0.1/lib/src/method_channel/method_channel_firebase.dart:88:9: Error: 'Cthrow' isn't a type.
        Cthrow coreNotInitialized();
        ^^^^^^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.0.1/lib/src/method_channel/method_channel_firebase.dart:88:16: Error: Expected ';' after this.
        Cthrow coreNotInitialized();
               ^^^^^^^^^^^^^^^^^^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-4.0.1/lib/src/method_channel/method_channel_firebase.dart:88:35: Error: Expected an identifier, but got ')'.
Try inserting an identifier before ')'.
        Cthrow coreNotInitialized();
                                  ^


FAILURE: Build failed with an exception.

* Where:
Script '/Users/kevinyang/Desktop/Developer/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/kevinyang/Desktop/Developer/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 52s
Exception: Gradle task assembleDebug failed with exit code 1

I'm suffering from this problem for a long time. May I know the cause of this? Thank you.

this error is coming from .pub-cache so just flutter clean, if the error still persist delete all the .pub-cache then

flutter clean

and pub get

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM