颤振)使用firebase有问题

Posted

技术标签:

【中文标题】颤振)使用firebase有问题【英文标题】:flutter) There's a problem using firebase 【发布时间】:2021-12-16 00:40:51 【问题描述】:

我将使用 Firebase 开发应用程序和网站。 但是,如果我添加 firebase 并尝试使用它,则会输出错误。

下面是android firebase在新项目中的添加和测试。

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

我将 google-services.json 放在 Android-app 文件夹中。 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

还有 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"),
        ),
      ),
    );
  

错了

    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

我被这个问题困扰了很长时间。我可以知道这是什么原因吗? 谢谢。

【问题讨论】:

【参考方案1】:

这个错误来自.pub-cache,所以只要清理干净,如果错误仍然存​​在,则删除所有 .pub-cache

颤抖干净

然后发布获取

【讨论】:

您好,感谢您的回答。 .pub-cache 的位置在哪里? 你用的是哪个操作系统? 从 pubspec.yaml 中的依赖项中移除包,运行 flutter packages get。然后再次将包添加到依赖项并运行flutter packages get。这个过程已经为我解决了过去的问题。 或flutter pub缓存修复 欢迎您......

以上是关于颤振)使用firebase有问题的主要内容,如果未能解决你的问题,请参考以下文章

如何使用颤振将视频添加到 Firebase 数据库

如何使用颤振从firebase实时检索数据

如何使用颤振将时间戳从 Firebase 转换为 DateTime

使用颤振从 Firebase 实时数据库中读取子节点的数量

是否可以使用 Firebase 存储将多个图像添加到 Firebase 数据库? - 颤振

尝试将 ExpansionPanelList/ExpansionPanel 与(Firebase)流一起使用时出现颤振错误