首页 > 解决方案 > adding Firebase packlages in flutter gives error

问题描述

I am trying to setup Firebase in my Flutter app. I have followed all the directions in the firebase website and also the flutter website to setup firebase including editing the pubspec.yaml file, editing the app level build.gradle file and the project level build.gradle file. when i run the app i get this error

/Users/tahrim/Desktop/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_web-0.1.1+2/android/src/main/java/io/flutter/plugins/firebase_core_web/FirebaseCoreWebPlugin 2.java:7: error: class FirebaseCoreWebPlugin is public, should be declared in a file named FirebaseCoreWebPlugin.java
public class FirebaseCoreWebPlugin implements FlutterPlugin {           
       ^                                                                
1 error                                                                 
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':firebase_core_web:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.        
                                                                        
* 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 2s                                                      
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                         2.8s
Exception: Gradle task assembleDebug failed with exit code 1

flutter doctor output

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, v1.17.1, on Mac OS X 10.15.5 19F101, locale en-BD)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[✓] IntelliJ IDEA Community Edition (version 2019.3.3)
 
[✓] Connected device (1 available)            

• No issues found!

my java version is openjdk version "1.8.0_252" how do i get rid of this error?

标签: javafirebasefluttergradle

解决方案


确保将这些添加到您的 gradle.properties 文件中

android.useAndroidX=true
android.enableJetifier=true

此外,您似乎使用的是旧版本的firebase_core_web. 尝试更新它。


推荐阅读