skip to Main Content

I tried to add Firebase to my Flutter project but I get this error.

tap to see error

I see lots of solutions here on this error. But none of them had helped. On the Firebase documentation, along steps, there is no step to add a classpath. When an error occurred, I added it to build.gradle (project level) according to the solutions here. But the error is the same.

And to be clear, I want to share my build.gradle (project-level) file:

codes with you.

And also you can see in the below picture, the plugin part of build.gradle (app-level) file:

this picture

Please, help me to solve that error.

2

Answers


  1. 1.Add Firebase to Your Flutter Project:
    Make sure you have added Firebase to your Flutter project by following these steps:
    Go to the Firebase Console (https://console.firebase.google.com/).
    Create a new project or select an existing one.
    Add your app to the Firebase project by clicking "Add app" and select the appropriate platform (Android).
    Follow the setup instructions, which will involve downloading a
    google-services.json file.
    Place this file in the android/app directory of your Flutter project.

    2.Configure build.gradle Files:
    Update the build.gradle files in your Flutter project as follows:

    In your project-level build.gradle (usually located in android/build.gradle), make sure you have the Google Services classpath:

        // ...
        classpath 'com.android.tools.build:gradle:7.2.1' // or the latest version
    }```
    
    n your app-level build.gradle (usually located in android/app/build.gradle), add the following at the bottom of the file:
    ```apply plugin: 'com.google.gms.google-services'```
    then after make these changes
    run ```flutter pub get ```
    and Double-check your dependencies in the `pubspec.yaml `
    ```dependencies:
      firebase_core: ^latest_version
      firebase_auth: ^latest_version
      firebase_database: ^latest_version
      firebase_messaging: ^latest_version```
    
    
    3.Check google-services.json:
    Ensure that the google-services.json file in your android/app directory is correctly configured for your Firebase project.
    
    4.Clean and Rebuild:
    Sometimes, issues can be resolved by cleaning and rebuilding the project. In Android Studio, you can find these options in the "Build" menu.
    
    Login or Signup to reply.
  2. Did you manage to fix it as im going through the same issue

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search