我將使用 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
我被這個問題困擾了很長時間。我可以知道這是什么原因嗎?謝謝你。
uj5u.com熱心網友回復:
這個錯誤來自.pub-cache所以只是flutter clean,如果錯誤仍然存??在,請洗掉所有.pub-cache然后
撲干凈
和酒吧得到
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/344860.html
上一篇:從子小部件更改父小部件中的屬性
