72

I try to connect Android project to Firebase but I get this error as I added the following to pubsec.yaml:

firebase_auth: ^0.16.0
cloud_firestore: ^0.13.5

when I gradle run and it is not working

Plugin project :firebase_core_web not found. Please update settings.gradle.
Plugin project :firebase_auth_web not found. Please update settings.gradle.
Plugin project :cloud_firestore_web not found. Please update settings.gradle.

Is there any solution for it

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Alex Ali
  • 1,339
  • 5
  • 23
  • 34

9 Answers9

133

In your android/app/build.gradle, update the following:

android {
    // ...
    defaultConfig {
        // ...
        minSdkVersion 16
    }
}

into:

android {
    // ...
    defaultConfig {
        // ...
        minSdkVersion 23
    }
}

Note:

You need to use minSdkVersion 23 when using firebase in flutter.

From the docs:

By default, Flutter supports Android SDK v16 (Jelly Bean, released 2012), but multidex doesn't really work with Jelly Bean (though, it's possible). Configuring Jelly Bean to work is beyond the scope of this codelab, so we'll change the minimum target SDK version from v16 to v21 (Lollipop, released 2014).

To change the minimum target SDK version:

  • Open android/app/build.gradle, then find the line that says minSdkVersion 16.
  • Change that line to minSdkVersion 21.
  • Save the file.

After upgrading, it should work fine. The settings.gradle file is provided to you when you create any new flutter project. For reference, this is how your settings.gradle file should be (default file no changes):

include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}

https://github.com/PeterHdd/Firebase-Flutter-tutorials/blob/master/firebase_storage_tutorial/android/settings.gradle


Explanation of settings.gradle:

Gradle is a build tool used for android projects, just like ant or maven, it uses groovy language or kotlin for scripting. In this case the above code is written using groovy and since groovy is a jvm language then it is able to use Java libraries. So basically include ':app' will add the project to the build(in groovy you can omit parenthesis for a method).

This line:

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

is getting the path to the flutter project that you created in your machine. For reference:

https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/ProjectDescriptor.html#getProjectDir-- https://docs.oracle.com/javase/8/docs/api/java/io/File.html#toPath-- https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html

This line:

def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')

Will create an empty file called .flutter-plugins, under the root of your flutter project. Then plugins.each{ name, path -> this is basically an iteration that will add the plugin name and the path of the plugin to the file .flutter_plugins, if the plugin is not found in that file you get the error in this question

.flutter-plugins file:

# This is a generated file; do not edit or check into version control.
cloud_firestore=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.13.6/
cloud_firestore_web=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-0.1.1+2/
firebase_auth=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.16.1/
firebase_auth_web=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-0.1.2/
firebase_core=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.4.4+3/
firebase_core_web=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/firebase_core_web-0.1.1+2/
firebase_database=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/firebase_database-3.1.5/
firebase_storage=/Users/<users>/.pub-cache/hosted/pub.dartlang.org/firebase_storage-3.1.5/
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • 7
    @GunJack you need minsdkversion 21 because firebase in flutter doesnt work with version 16, you can see here https://codelabs.developers.google.com/codelabs/flutter-firebase/#3.. All you have to do is create a new flutter project, the settings.gradle in the other answer is already provided to you when you create a new flutter project – Peter Haddad Jun 07 '20 at 12:48
  • An explanation on what this piece of code does will be greatly appreciated. Thanks. – GunJack Jun 07 '20 at 14:36
  • Thank you for the detailed explanation – GunJack Jun 07 '20 at 18:22
  • But my settings.gradle has refrences to flutter sdk and other stuff. Should I overwrite that with the code you provided or just append? – GunJack Jun 07 '20 at 18:27
  • I'm not sure wat u have in settings.gradle but this flutter_plugins file has to be created try to append to see if it works – Peter Haddad Jun 07 '20 at 18:55
  • I commented out what was in there earlier. And put these files in. Its working now without issues. – GunJack Jun 07 '20 at 21:07
  • This is working. If you didnt have settings gradle file as above. replace it with above gradle settings. (Its worked for me) – dilshan Aug 14 '20 at 07:01
  • 1
    Thank you so much for the detailed explanation @PeterHaddad – Vimukthi Bandara Aug 18 '20 at 05:18
80

Change file settings.gradle to this

include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}
TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
user13578342
  • 809
  • 4
  • 2
20

Please add this in flutter app -> android -> settings.gradle

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

    def plugins = new Properties()

    def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
    if (pluginsFile.exists()) {

        pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
    }

    plugins.each { name, path ->
        def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
        include ":$name"
        project(":$name").projectDir = pluginDirectory
    }
Ahmed Othman
  • 311
  • 1
  • 6
  • Don't add this to the end of the default settings.gradle file - you can simply replace the whole file with this – kilkfoe Jun 14 '21 at 16:35
3

My settings worked with the following versions.

pubspec.yaml

firebase_auth: ^0.14.0+5
cloud_firestore: ^0.12.9+5

I also added (pubspec.yaml) to silence the warnings.
firebase_core: ^0.4.5
firebase_analytics: ^5.0.2

build.gradle (root dir)
classpath 'com.google.gms:google-services:4.3.3'

build.gradle (app dir)
minSdkVersion 23
targetSdkVersion 28

Then I added this at the bottom of build.gradle
apply plugin: 'com.google.gms.google-services'

The final thing is to run the Terminal command:
$flutter packages get

After building the project - you wait 15 seconds and it will show a
"Congratulations, you've successfully added Firebase to your app!"
message on your Firebase Console.

enter image description here

Baxter
  • 312
  • 4
  • 6
2

JUST add this to your settings.gradle file -

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()

def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {

    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }

}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}
Dpedrinha
  • 3,741
  • 3
  • 38
  • 57
Ash
  • 39
  • 2
2

Just make the

minSdkVersion 21

Mohamed Reda
  • 1,207
  • 13
  • 21
1

In the addition to Peter's answer I misplaces this line. The correct one is the bottom of the file

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

joe
  • 8,383
  • 13
  • 61
  • 109
0

This could be one of the dependencies version is not matching. Please make sure your are using all latest versions of lib in your pubspec.yaml

You can refer the latest version of dependencies from PubDev

Dhrumil Shah
  • 2,128
  • 5
  • 23
  • 37
0

I got the same errors:-

Plugin project :firebase_core_web not found. Please update settings.gradle. Plugin project :cloud_fireenter code heresenter code heretore_web not found. Please update settings.gradle. Plugin project :firebasenter code heree_auth_web not found. Please update settings.gradle.

I resolved this by following process:-

Go to your app level gradle file and see there targetSdkVersion, if it has 16 or less then update to new latest version serching from this link https://developer.android.com/guide/topics/manifest/uses-sdk-element. It will be helpful.