java - 如何修复错误:未找到 ID 为“com.google.gms:google-services:4.2.0”的插件
问题描述
我环顾四周以解决此错误,但仍未找到任何解决方案。
我曾尝试切换到其他 google-services 版本,并且根本不包括任何版本,但没有一个有效。网上找到的解决方案也没有解决问题。
我的 build.gradle (项目)代码是:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的 build.gradle (Module: app) 代码是:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.whatsappclone"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.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'
}
apply plugin: 'com.google.gms:google-services:4.2.0'
解决方案
以下是可以帮助您的步骤:
1.首先将“com.android.tools.build:gradle”版本从“3.4.0”降级为“3.3.2”
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.打开“gradle-wrapper.properties”并使用“5.1.1-all”版本更新您的distributionUrl url,如下所示
#Mon May 06 12:26:03 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
3.打开“gradle.properties”并添加以下两行
android.useAndroidX=true
android.enableJetifier=true
4.然后更新您的应用程序级别gradle,如下所示:
问题是您使用了这个符号“:”而不是“。” 申请“谷歌服务”
错误的插件实现 => 应用插件:'com.google.gms:google-services'
正确的插件实现 => 应用插件:'com.google.gms.google-services'
最终分级:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ankit.gradletest511"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
apply plugin: 'com.google.gms.google-services'
推荐阅读
- python - BS4 find_all 与 Genius Lyrics 中的 mini_card-title 类不匹配
- vue.js - 使用 v-bind 将点击事件绑定到子组件
- java - 为什么我的作业中会出现“Context = NullPointerException”错误?
- r - 如何计算发生之间的时间(和发生的持续时间)
- docker - 本地机器上的领事健康检查失败
- theos - 修复错误“初始化元素不是编译时常量”
- maven - 运行“mvn test”失败:无法加载 mojo 'test'(或其所需组件之一)
- c# - 在 EF 中使用表达式返回方法
- python - pygame.transform.scale does not work on the "game" surface
- typescript - 函数返回对象类型