无法找到方法“com.android.build.api.variant.SourceDirectories$Flat com.android.build.api.variant.Sources.getByName(java.lang.String)”

问题描述 投票:0回答:1

我在处理 Android 项目时遇到问题。我收到以下错误消息:

Unable to find method 'com.android.build.api.variant.SourceDirectories$Flat 'com.android.build.api.variant.Sources.getByName(java.lang.String)''com.android.build.api.variant.SourceDirectories$Flat com.android.build.api.variant.Sources.getByName(java.lang.String)'

我正在尝试在我的 Android Studio 项目中使用 Firebase。当我在 build.gradle (模块)中添加此代码时,它给了我这个错误

id 'com.google.gms.google-services'

我认为我的应用程序有问题或其他什么问题,所以我尝试制作新项目并尝试链接 firebase。但它仍然是错误

java android firebase gradle sdk
1个回答
0
投票

出现此错误的原因是 Android Gradle 插件和 Google 服务插件之间的版本不匹配。要修复此问题,请确保两个插件兼容。 Google Services 插件的最新版本是 4.3.10,可与 Android Gradle 插件版本 7.0.4 配合使用。要更新这些插件,只需更新您的项目级 build.gradle 文件即可。

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

在您的应用程序级 build.gradle 文件中,更新底部的 Google 服务插件版本:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    // your android configuration
}

dependencies {
    // your dependencies
}

apply plugin: 'com.google.gms.google-services' // Google Services plugin

dependencies {
    classpath 'com.google.gms:google-services:4.3.10'
}

进行这些更改后,将您的项目与 Gradle 文件同步,错误应该会得到解决。

© www.soinside.com 2019 - 2024. All rights reserved.