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

Gradle构建失败:无法找到com.android.application:8.2.1插件

解决无法找到com.android.application:8.2.1插件的构建错误

以下是针对性的排查和解决步骤:

1. 确认仓库配置完整性

打开项目根目录的settings.gradle.kts文件,确保已添加Google仓库(Android Gradle Plugin仅发布在该仓库),配置示例:

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

如果缺少google()仓库,插件将无法被检索到。

2. 验证AGP与Gradle版本兼容性

AGP 8.2.1要求Gradle版本在8.0~8.3之间,检查gradle/wrapper/gradle-wrapper.properties中的distributionUrl:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip

若版本不匹配,修改后同步项目。

3. 检查插件声明格式

确认根目录build.gradle.kts中的插件声明无语法错误,正确写法如下:

plugins {
    id("com.android.application") version "8.2.1" apply false
    id("org.jetbrains.kotlin.android") version "1.9.20" apply false // 若使用Kotlin需同步版本
}

注意不要拼写错误插件ID或版本号。

4. 清理本地缓存

  • 通过Android Studio操作:File > Invalidate Caches... > 勾选Clear file system cache and local history > 点击Invalidate and Restart
  • 手动清理:删除项目根目录的.gradle文件夹、所有模块的build文件夹,然后重新同步项目。

5. 排查网络问题

若网络无法访问Google仓库,可配置国内镜像仓库,在settings.gradle.kts的repositories块中添加:

maven { url = uri("https://maven.aliyun.com/repository/google") }
maven { url = uri("https://maven.aliyun.com/repository/public") }

替换原有仓库或添加在前面优先检索。

内容的提问来源于stack exchange,提问作者Vision

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 21:33:16