经过发现,这种方法可以解决该问题。
请在项目级Gradle中更新您的类路径:com.google.gms:google-services:2.1.0
到类路径com.google.gms:google-services:3.0.0
必需品:Android Studio和Google Play服务的最新版本
您可以按照以下步骤将插件添加到项目中,即通过更新顶级build.gradle和应用程序级别的build.gradle文件:
classpath 'com.google.gms:google-services:3.0.0'
喜欢
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
}
}
现在,您需要为Google Play服务添加一个依赖项。在您的应用的build.gradle文件中添加以下内容:
compile 'com.google.android.gms:play-services:9.6.1'
最后
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "// set Yours"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.android.support:appcompat-v7:24.2.0'
}
apply plugin: 'com.google.gms.google-services'
build.gradle
文件。你可以将其作为问题进行询问。 - IntelliJ Amiyaclean-rebuild-gradle
。 - IntelliJ AmiyaGCM已被重新命名为Firebase Cloud Messaging (FCM),如果您想使用com.google.android.gms:play-services:9.0.0
,请阅读本文FCM。如果要生效,请修改您的build.gradle
文件以使用该插件。
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.0.0'
}
}
Error:Execution failed for task ':app:processDebugGoogleServices'。> 缺少api_key/current_key对象
。 - Shajeel Afzalcom.google.android.gms
更新到版本9.2.0
?
SDK Manager没有显示任何更新,因此我必须手动更新。 - mrid我发现最简单的方法是使用最新版本。
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//apply plugin: 'com.google.gms.google-services' //Firebase
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
compile 'com.google.firebase:firebase-auth:10.2.6'
compile 'com.google.android.gms:play-services-auth:10.2.6' //10.2.6
compile 'com.google.firebase:firebase-core:10.2.6' // used for FCM
compile 'com.google.firebase:firebase-messaging:10.2.6' // used for FCM
testCompile 'junit:junit:4.12'
// apply plugin: 'com.google.gms.google-services'
}
解释
apply plugin: 'com.google.gms.google-services' // 在底部添加此行.
apply plugin: 'com.google.gms.google-services'
// 在底部添加此行.然后,将以下内容添加到依赖项中
compile 'com.google.firebase:firebase-auth:10.2.6'
// 确保这是最新版本.
compile 'com.google.android.gms:play-services-auth:10.2.6'
//10.2.6 最新版
compile 'com.google.firebase:firebase-core:10.2.6'
// 用于 FCM
compile 'com.google.firebase:firebase-messaging:10.2.6'
// 用于 FCM
假设您使用的是最新的 firebase-auth 10.2.6(即今天的最新版本为2017年5月25日),但同时您正在使用 play-services-auth:9.0.0 或更低版本,那么它们都无法建立连接并显示错误。
希望这可以帮助到您。
当将Play服务更改为10.2.1以上的版本时,我的依赖项开始无法解析。
我发现更改以下Maven URL可以解决此问题:
maven { url 'https://raw.githubusercontent.com/onepf/OPF-mvn-repo/master/' }
到
maven { url 'https://github.com/onepf/OPF-mvn-repo/raw/master/' }
可能是URL的更改避免了在gradle或maven中进行缓存,从而解决了这个问题。
compile 'com.google.android.gms:play-services:9.0.0' //or latest version
play-services:9.0.0
的POM时,我没有看到play-services-measurement
作为依赖项,并且没有play-services-measurement
的9.0.0
版本。你是否手动请求了play-services-measurement
?如果没有,请尝试清理项目,或使用带有--refresh-dependencies
开关的命令行gradle
构建,以尝试停止寻找play-services-measurement
。总的来说,与其使用“厨房水槽”式的play-services
,不如使用更专注的依赖项(你已经注释掉的那些)。 - CommonsWareplay-services
不再需要它,因此必须有其他东西请求它。 - CommonsWare