76

I'm trying to add firebase cloud storage to my app. Below is the app build.gradle. But it says: Failed to resolve: com.google.firebase:firebase-core:16.0.1. Why? There is no firebase-core in the dependencies at all.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.louise.udacity.mydict"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.google.cloud:google-cloud-storage:1.31.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
}

apply plugin: 'com.google.gms.google-services'
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Louise L.
  • 797
  • 1
  • 6
  • 10
  • 1
    if you are using kotlin than: Replace: implementation 'com.google.firebase:firebase-core:16.0.0' with: kapt 'com.google.firebase:firebase-core:16.0.0' and your top level gradle file add classpath 'com.google.gms:google-services:4.0.1' – Dilip May 31 '18 at 07:18

14 Answers14

116

From the docs:-

Your app gradle file now has to explicitly list com.google.firebase:firebase-core as a dependency for Firebase services to work as expected.

Add:

 implementation 'com.google.firebase:firebase-core:16.0.1'

and in top level gradle file use the latest version of google play services:

classpath 'com.google.gms:google-services:4.0.2'

https://firebase.google.com/support/release-notes/android

https://bintray.com/android/android-tools/com.google.gms.google-services

Note:

You need to add the google() repo in the top level gradle file, as specified in the firebase docs and also it should be before jcenter():

 buildscript {
  repositories {
          google()
          jcenter()
      }



dependencies {
  classpath 'com.android.tools.build:gradle:3.1.3'
  classpath 'com.google.gms:google-services:4.0.2'
   }
}

allprojects {
     repositories {
              google()
             jcenter()
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
 }

https://firebase.google.com/docs/android/setup

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • 6
    I added firebase-core, but same error occurs. btw, I used firebase assistant in android studio to add firebase cloud. – Louise L. May 29 '18 at 14:08
  • it also says: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html. But i double checked all build.gradle files. I'm using implementation instead of comple for all dependencies. – Louise L. May 29 '18 at 14:10
  • 1
    clean and rebuild the project, what android version plugin are u using? – Peter Haddad May 29 '18 at 15:47
  • 1
    yes, I tried "clean" and "rebuild", same result. What do you mean by "android version plugin"? So if I delete firebase-storage and firebase-auth dependencies, the error disappeared. Once adding the 2 dependencies back, it looks like something is forcing firebase-core to 16.0.1, then failed. – Louise L. May 29 '18 at 15:58
  • 1
    this `classpath 'com.android.tools.build:gradle:3.1.0'` and this `classpath 'com.google.gms:google-services:4.0.1'` – Peter Haddad May 29 '18 at 16:02
  • 1
    oh, my "com.google.gms:google-services" was 3.XX, i just upgraded to 4.0.1, the problem solved. Thanks so much!! – Louise L. May 29 '18 at 16:30
  • I had same issue, for my case I just changed the version from 16.0.0 to "11.0.4" because that was available version for play-services in my system. So people facing similar issue don't just change versions randomly as its not gonna work. – sanky Aug 18 '18 at 16:26
  • u need to upgrade google-service plugin to version 4.0.2 to be able to use 16.0.1 @sanky No one is upgrading randomly everything is explained. If you want to use 16.0.1 then you need to update google-service plugin – Peter Haddad Aug 18 '18 at 16:34
  • Adding google() in repositories of allprojects manually worked for me... – Shachi Feb 06 '19 at 08:28
  • 1
    @Shachi yup as I said in the Note you need to add the `google() ` to be able to use firebase services. – Peter Haddad Feb 06 '19 at 17:31
  • Yup.. +1 for that... simple and concise @PeterHaddad – Shachi Feb 07 '19 at 05:58
  • Just adding this: classpath 'com.google.gms:google-services:4.0.2' solved my problem. Thanks. – seymatanoglu Apr 03 '19 at 19:00
6

Since May 23, 2018 update, when you're using a firebase dependency, you must include the firebase-core dependency, too.

If adding it, you still having the error, try to update the gradle plugin in your gradle-wrapper.properties to 4.5 version:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip

and resync the project.

bra_racing
  • 622
  • 1
  • 8
  • 32
  • 1
    I added firebase-core, but same error occurs. btw, I used firebase assistant in android studio to add firebase cloud. – Louise L. May 29 '18 at 14:08
  • +--- com.google.firebase:firebase-core:16.0.0 -> 16.0.1 FAILED I tried to run gradle dependencies, and it displayed the entry above. Looks like it intentionally convert 16.0.0 (which i declared in build.gradle) to 16.0.1. Do you know why it happens and how to modify the settings? – Louise L. May 29 '18 at 15:36
  • Same here. It is working just fine with 16.0.0, but fails when I upgrade to 16.0.1. I am using all the latest Android Gradle and GMS configurations, plus gradle 4.7. Any ideas? – racs Jul 05 '18 at 02:23
  • Yes, gradle-4.5 was the thing I was in need. Using 4.4, I was getting the error. – Md Tarik Mahmud Dec 12 '18 at 14:01
  • This version is old. Please don't run into compatibility issues. Please upgrade everything to the latest. – Abhinav Saxena Jan 09 '19 at 12:46
6

Add maven { url "https://maven.google.com" } to your root level build.gradle file

repositories {
    maven { url "https://maven.google.com" }
    flatDir {
        dirs 'libs'
    }
}
Morteza Jalambadani
  • 2,190
  • 6
  • 21
  • 35
Andy
  • 61
  • 1
  • 2
6

As @Peter Haddad mentioned above,

To fix this issue I followed Google firebase integration guidelines and did the following changes in my app/build.gradle and project/build.gradle

Follow below mentioned link if you have any doubts

https://firebase.google.com/docs/android/setup

changes in app/build.gradle

implementation 'com.google.android.gms:play-services-base:15.0.2'
implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.google.firebase:firebase-messaging:17.4.0"

Changes in Project/build.gradle

repositories {

        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.2.0'// // google-services plugin it should be latest if you are using firebase version 16.0 +
       
    }
    allprojects {
    repositories {
         google()// add it to top instead of bottom or somewhere in middle
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://maven.google.com'
        }
       
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        
    }
}
kaushal
  • 903
  • 10
  • 17
5

I get the same issue and i solved it by replacing :

implementation 'com.google.firebase:firebase-core:16.0.1'

to

implementation 'com.google.firebase:firebase-core:15.0.2'

and everything solved and worked well.

Salim Lachdhaf
  • 1,073
  • 1
  • 9
  • 21
3

What actually was missing for me and what made it work then was downloading'Google Play services' and 'Google Repository'

Go to: Settings -> Android SDK -> SDK Tools -> check/install Google Play services + repository

SDK Tools Settings SS

Hope it helps.

Diego Feder
  • 79
  • 1
  • 4
2

I was able to solve the issue by following these steps-

1.) This error occurs when you didn't connect your project to firebase. Do that from Tools->Firebase if you are using Android studio version 2.2 or above.

2.) Make sure you have replaced the compile with implementation in dependencies in app/build.gradle

3.) Include your firebase dependency from the firebase docs. Everything should work fine now

GianhTran
  • 3,443
  • 2
  • 22
  • 42
2

This is rare, but there is a chance your project's gradle offline mode is enable, disable offline mode with the following steps;

  • In android studio, locate the file tab of the header and click
  • In the drop own menu, select settings
  • In the dialog produced, select "Build, Execution, Deploy" and then select "Gradle"
  • Finally uncheck the "offline work" check box and apply changes

If this doesn't work leave a comment describing your Logcat response and i'll try to help more.

EAM
  • 361
  • 2
  • 5
0

In my case it was resolved by changing the compileSdkVersion and targetSdkVersion from 26 to 27

DeadStar
  • 99
  • 1
  • 7
0

If you use Firebase in a library module, you need to apply the google play services gradle plugin to it in addition to the app(s) module(s), but also, you need to beware of version 4.2.0 (and 4.1.0) which are broken, and use version 4.0.2 instead.

Here's the issue: https://github.com/google/play-services-plugins/issues/22

Louis CAD
  • 10,965
  • 2
  • 39
  • 58
0

if you are using

compileSdkVersion 23

in app-level gradle, and

classpath 'com.android.tools.build:gradle:2.1.0'

in project-level gradle and you have added the google-services.json file to your project.

you need to add just below code

maven {
   url "https://maven.google.com"
}

at below of jcenter() in repositories blocks in project-level gradle file here are my gradle files:

project-level gradle file:

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and app-level gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.moslem.amazonlikeapp"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
0

Just add below code and update all firebase versions that will work

 implementation 'com.google.firebase:firebase-core:17.2.0'
Praveen
  • 430
  • 3
  • 11
0

If you receive an error stating the library cannot be found, check the Google maven repo for your library and version. I had a version suddenly disappear and make my builds fail.

https://maven.google.com/web/index.html

BK-
  • 527
  • 7
  • 19
0

Go to

Settings -> Android SDK -> SDK Tools ->

and make sure you install Google Play Services

Malith Ileperuma
  • 926
  • 11
  • 27