添加Baseline Profile模块时遇org.gradle.api.plugins.UnknownPluginException怎么解决
解决org.gradle.api.plugins.UnknownPluginException(com.android.test插件找不到)
1. 确保settings.gradle配置Google Maven仓库
com.android.test插件属于Android Gradle Plugin(AGP)组件,托管在Google Maven仓库,而非仅Gradle Central。打开项目根目录的settings.gradle(或settings.gradle.kts),确认pluginManagement和dependencyResolutionManagement区块中都包含google()仓库,且放在mavenCentral()之前:
pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } }
2. 验证AGP版本兼容性
确保项目中AGP相关插件(com.android.application、com.android.test)的版本与Gradle、Android Studio版本匹配:
- AGP 8.4.0需要搭配Gradle 8.6及以上版本
- 若你的Android Studio版本低于Hedgehog(2023.1.1),建议将AGP版本降级到对应稳定版,比如改为
8.2.2:
plugins{ id 'com.android.test' version '8.2.2' apply false id 'org.jetbrains.kotlin.android' version '1.9.22' apply false id 'androidx.baselineprofile' version '1.2.3' apply false id 'com.android.application' version '8.2.2' apply false }
3. 强制刷新Gradle缓存
若配置无误仍报错,执行以下操作:
- 点击Android Studio右上角的「Sync Project with Gradle Files」按钮
- 若无效,删除项目根目录的
.gradle文件夹和各模块下的.gradle文件夹,重新同步项目
内容的提问来源于stack exchange,提问作者Mohit Singh
相关产品推荐
相关产品推荐

