我正在Android Studio Bumblebee中创建一个新应用程序,默认使用settings.gradle
中的新的Groovy DSL插件管理。
我需要能够使用Google Play Services来启用Firebase功能,但是我在使用这里的文档应用com.google.gms.google-play-services
插件时遇到了一个构建错误:Google Play Services Readme
我在我的settings.gradle
文件中添加了以下内容:
pluginManagement {
repositories {
gradlePluginPortal()
google()
}
plugins {
id 'com.android.application' version '7.1.0-alpha13'
id 'com.android.library' version '7.1.0-alpha13'
id 'org.jetbrains.kotlin.android' version '1.5.31'
id 'com.google.gms.google-services' version '4.3.10'
}
}
和以下的应用程序的build.gradle
文件:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
但是当我构建应用程序时,我得到以下UnknownPluginException
:
Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.10')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
我也尝试了classpath
等的遗留方法,但这导致了一个更长的关于依赖解析的错误消息。
我不知道我做错了什么。
通过使用Android Studio Bumblebee新的Groovy DSL插件管理,在build.gradle(Project:) plugins{}部分添加下面一行并同步项目将解决您的问题。
id 'com.google.gms.google-services' version '4.3.10' apply false
你的build.gradle(Project:)看起来像
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.dagger.hilt.android' version '2.41' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false
id 'com.google.firebase.crashlytics' version '2.8.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
你的build.gradle(Module:)看起来像
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
id 'com.google.dagger.hilt.android'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
android {
compileSdk 32
signingConfigs {
config {
enableV3Signing true
enableV4Signing true
}
}
}
设置。gradle(Project Settings)看起来像
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyApp"
include ':app'
将google-services
插件添加到plugins {}
块会导致错误。我找到的另一种方法是:
- 首先,在你的根构建文件中(不是app文件夹中的那个),在
buildscript {}
块内,添加这个
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}
- 在app文件夹中的构建文件中,像这样应用插件,
apply plugin: 'com.google.gms.google-services'
在步骤1中,使用mavenCentral()
是必要的,因为google-services
插件从maven central下载链接的依赖项,如gson
:)