我尝试在 Android Studio 中运行我的 Android 应用程序,但遇到以下错误:
Plugin [id: 'com.android.application', version: '8.0.2', apply: false] was not found in any of the following sources:
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '8.0.2', apply: false] 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.0.2')
Searched in the following repositories:
Gradle Central Plugin Repository
at Program.execute(Unknown Source)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.lambda$initAction$6(GradleModelFetchAction.java:184)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.callWithSpan(GradleOpenTelemetry.java:73)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.callWithSpan(GradleOpenTelemetry.java:61)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.initAction(GradleModelFetchAction.java:183)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.doExecute(GradleModelFetchAction.java:138)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.lambda$execute$1(GradleModelFetchAction.java:103)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.callWithSpan(GradleOpenTelemetry.java:73)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.callWithSpan(GradleOpenTelemetry.java:61)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.lambda$execute$2(GradleModelFetchAction.java:102)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.withOpenTelemetry(GradleModelFetchAction.java:113)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.lambda$execute$3(GradleModelFetchAction.java:101)
at com.intellij.gradle.toolingExtension.impl.util.GradleExecutorServiceUtil.withSingleThreadExecutor(GradleExecutorServiceUtil.java:18)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.execute(GradleModelFetchAction.java:100)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.execute(GradleModelFetchAction.java:36)
以下是我的 build.gradle.kts 文件的相关部分: 项目级
build.gradle.kts:
plugins {
id("com.android.application") version "8.0.2" apply false
id("org.jetbrains.kotlin.android") version "1.8.21" apply false
}
模块级
app/build.gradle.kts:
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt") // For annotation processing
}
Gradle 包装属性 (
gradle-wrapper.properties
):
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
settings.gradle.kts:
rootProject.name = "MyActualAppName"
include(":app")
注意:项目名称不是真实的。
当我使用
com.android.application:8.7.1
、 org.jetbrains.kotlin.android:2.0.21
并运行 AGP 升级助手时:
Plugin [id: 'com.android.application', version: '8.7.1', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:8.7.1')
Searched in the following repositories:
Gradle Central Plugin Repository
我已使缓存失效并重新启动 Android Studio。我正在使用 Android Studio Ladybug(2024.2.1 补丁 1)。是什么原因导致此问题?我该如何解决?任何帮助将不胜感激!
settings.gradle.kts 似乎缺少最重要的部分,即可以找到其他 gradle 文件中引用的工件的存储库。
在 Android Studio 中创建新项目时,自动创建的
settings.gradle.kts
如下所示:
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyActualAppName"
include(":app")
我不知道为什么你缺少大部分内容,但添加它应该可以解决你遇到的问题。