You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle同步报错:找不到com.google.firebase.firebase-perf插件

解决Firebase Performance插件Gradle同步错误

错误原因

你遇到的UnknownPluginException核心问题有两个:

  1. 插件ID错误:在根目录build.gradle的plugins块中,你使用了com.google.firebase.firebase-perf作为插件ID,但Firebase Performance Gradle插件的正确ID是com.google.firebase.firebase-perf-plugin
  2. 版本不兼容:插件版本1.4.2和你当前使用的Firebase BOM 32.4.0版本差距过大,会导致兼容性问题

修复方案

方案1:使用Gradle Plugins DSL(推荐,适配Gradle 7.0+)

  1. 修改根目录build.gradle
    替换plugins块中的错误插件配置,使用正确ID和匹配BOM的版本:

    plugins {
        id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
        // 修正插件ID并使用匹配BOM的版本
        id 'com.google.firebase.firebase-perf-plugin' version '2.9.6' apply false
    }
    

    版本说明:Firebase BOM 32.4.0对应的Performance插件版本为2.9.6,和你当前使用的Crashlytics插件版本一致,确保依赖兼容性

  2. 修改app模块build.gradle
    替换旧的插件引用方式,同时移除重复的插件声明:

    plugins {
        id 'com.android.application'
        id 'com.google.firebase.firebase-perf-plugin'
        id 'com.google.android.gms.oss-licenses-plugin'
        id 'com.google.gms.google-services'
        id 'com.google.firebase.crashlytics'
        id 'kotlin-android'
        id 'kotlin-parcelize'
        id 'kotlin-kapt'
    }
    

    注意:删除重复的apply plugin: 'com.android.application',避免重复应用插件导致的异常


方案2:使用传统buildscript Classpath方式(兼容旧Gradle版本)

  1. 修改根目录build.gradle
    删除plugins块中的错误插件行,在buildscript的dependencies中添加Performance插件的classpath:

    buildscript {
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:7.3.1'
            classpath 'com.google.gms:google-services:4.3.15'
            classpath 'com.google.android.gms:oss-licenses-plugin:0.10.6'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
            classpath "com.squareup:javapoet:1.13.0"
            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.6'
            classpath 'com.google.firebase:firebase-perf-gradle:2.9.6' // 添加这一行
            classpath 'org.jacoco:org.jacoco.core:0.8.8'
            classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.5.0.2730"
        }
    }
    
    plugins {
        id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
        // 移除之前错误的com.google.firebase.firebase-perf配置行
    }
    
  2. 修改app模块build.gradle
    保留原有的插件引用,但移除重复的apply plugin: 'com.android.application':

    apply plugin: 'com.android.application'
    apply plugin: 'com.google.firebase.firebase-perf'
    apply plugin: 'com.google.android.gms.oss-licenses-plugin'
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'com.google.firebase.crashlytics'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-parcelize'
    apply plugin: 'kotlin-kapt'
    

额外检查

确保你的settings.gradle中配置了Google仓库,Gradle才能正确拉取插件:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

完成以上修改后,重新同步Gradle即可解决插件找不到的问题。

内容的提问来源于stack exchange,提问作者DJ-DOO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 01:58:14