Unable to resolve dependency for ':app@debug/c

2020-07-31 06:19发布

问题:

Currently, I am working on an android chat application. I want to add FCM in my app. But I am always getting this gradle error. From what I have read, the firebase auth, database and messaging dependency version should match. I have tried every version, still, the same error occurs.

回答1:

To solve this, please change the following line of code:

com.google.firebase:firebase-auth:16.0.1

to

com.google.firebase:firebase-auth:16.0.2

and add:

com.google.firebase:firebase-core:16.0.1

Which is mandatory now. Don't also forget to add:

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

At the end of your file and the following line of code:

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

Into your build.gradle file (Project).

PS. If you are using Firebase-UI auth, add also this line of code:

com.firebaseui:firebase-ui-auth:4.0.1


回答2:

You must have forgotten to add google() // Google's Maven repository in build.gradle.

allprojects {
   // ...
   repositories {
       // ...
       google() // Google's Maven repository
   }
}

Here is the comment from firebase docs:

// Getting a "Could not find" error? Make sure you have

// added the Google maven respository to your root build.gradle

Here is the reference: link



回答3:

Add Maven to your project.gradle in repositories LIKE THIS

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


回答4:

Late post, but will help to someone... Change your project level build.gradle file

 // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'

    }
}

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

Make changes in app-level build.gradle file

dependencies {
    implementation 'com.google.android.gms:play-services:+'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    //implementation 'com.google.firebase:firebase-ads:15.0.1'
    implementation 'com.google.firebase:firebase-ads:17.1.2'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-database:16.1.0'
}