报错

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '8.4.0', apply: false] was not found in any of the following sources:

问题背景介绍

1、IDE软件版本:Android Studio Koala | 2024.1.1 Canary 8

Android Studio Koala | 2024.1.1 Canary 8
Build #AI-241.15989.150.2411.11792637, built on May 2, 2024
Runtime version: 17.0.10+0--11609105 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Registry:
  ide.experimental.ui=true
Non-Bundled Plugins:
  com.markskelton.one-dark-theme (5.11.0)
  com.jetbrains.darkPurpleTheme (1.3)
  com.samdark.intellij-visual-studio-code-dark-plus (2.8)
  monokai-pro (1.10)

2、问题:新建项目后,没有任何修改,但是gradle sync报错,直接问题是gradle插件版本问题。

前提:因为默认的maven加载太慢,就配置了阿里云镜像,然后报错了。

Build file 'E:\Workspace\TestTool\build.gradle.kts' line: 2

Plugin [id: 'com.android.application', version: '8.5.0-alpha08', apply: false] was not found in any of the following sources:

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '8.4.0'] 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.android.application:com.android.application.gradle.plugin:8.4.0') 

Searched in the following repositories:
    maven(https://maven.aliyun.com/repository/central)
    maven2(https://maven.aliyun.com/repository/public)
    maven3(https://maven.aliyun.com/repository/gradle-plugin)
    Google
    MavenRepo
    Gradle Central Plugin Repository

分析记录

1、找到报错值——发现却不是版本问题,是maven仓库

新建项目没有设置,默认配置的 $versions.agp就是'8.5.0-alpha08'。

  •  app的build.gradle默认配置的还是java8
//app\build.gradle.kts

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
  • 更新为sdk33可匹配的Java版本,如Java 17.
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

还没解决

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐