Failed to resolve 'com.google.firebase:firebase-messaging:11.0.4' in Android Studio 2.3.3

拜拜、爱过 提交于 2019-12-23 07:52:25

问题


I want to Set up a firebase Cloud Messaging Client App on Android studio, I am using latest version of Android studio(2.3.3) and my android SDK is fully updated.

Here is my project gradle file:

 buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:3.1.0'
        classpath 'com.android.tools.build:gradle:2.3.3'
    }
}

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

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

and this is my app build gradle file :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "ir.digiwindow.driver.gps_status"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-messaging:11.0.4'


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

and I always give this error :

Error:(30, 13) Failed to resolve: compile 'com.google.firebase:firebase-messaging:11.0.4'

The intresting point here is that when I change version from 11.0.4 to 10.0.1 no error occurs and gradle build successfully! I read all realated posts in stackoverflow and google developer site, but this error still exists! Any ideas welcome...

Edit 1: when I go to look for updates I don't see any option about updating google play service here in the image: enter image description here


回答1:


I have faced the same problem, I have resolved it by updating two things

  1. Google play service
  2. Google repository




回答2:


Mr Jan, Please follow below link its clearly says that->

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

Prerequisites-

  • A device running Android 4.0 (Ice Cream Sandwich) or newer, and Google Play services 11.6.0 or higher
  • The Google Play services SDK from the Google Repository, available in the Android SDK Manager
  • The latest version of Android Studio, version 1.5 or higher

So Upgrade your Google Play Services and Google Repository in SDK Manager

Open Android studio > Go to File > Settings > Appearance and Behavior > System Setting > Android SDK > SDK Tools > Update

1- Google Play Services and

2- Google Repository under Support Repository




回答3:


As Dileep mentioned from the documentation, you need to have Google Play Services 11.0.4 or higher installed.

Just open the SDK Manager,
Then Android SDK (on the left hand menu)
Then to the SDK Tools Tab and update Google Play Services, which is currently in version 43 (2017-08-10).

That solved it for me.




回答4:


Try to add Firebase features through firebase Assitance go to Tools then Firebase and then select which feature you want to add like Realtime Database. It will automatically add the compile dependencies to your project. I did the same and solved my problem.




回答5:


It should be this way:

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.1'

    classpath 'com.google.gms:google-services:3.1.1' // ADD this
}

app: (11.8.0)

implementation 'com.google.firebase:firebase-messaging:11.8.0' // ADD this



回答6:


Un Tick Offline Gradle Build will solve this issue if any of the above solution not working




回答7:


I had the same problem. Later discovered I copied the line exactly from firebase docs.

Classpath 'com.google.gms:google-services:3.1.1'

Notice the CAPITAL 'C'.

it should be

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

with lower case 'c'.

Dumb mistake but easily unnoticeable.




回答8:


Gradle version, firebase services version and google-play-services versions should be same when using. you may not use gradle 2.x with firebase core 16.x for example.




回答9:


I had the same problem and I just changed the version from 11.0.4 to 10.0.1 and the error went away. Just try it, it may be helpful.




回答10:


The solution is to update to the latest version of the classpath of com.google.gms:google-services

which is hinted by Android Studio in file build.gradle of the project



来源:https://stackoverflow.com/questions/45617237/failed-to-resolve-com-google-firebasefirebase-messaging11-0-4-in-android-stu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!