Android Studio升级API34时找不到com.android.application:8.5.0插件
问题背景
使用Android Studio将应用升级到API 34并发布到Google Play商店时,遇到Gradle插件解析错误。
错误信息
ERROR: * 位置: 构建文件 '...android\app\build.gradle' 第3行 * 问题概述: 未在以下任何来源中找到插件 [id: 'com.android.application', version: '8.5.0', apply: false]: - Gradle核心插件(插件不在 'org.gradle' 命名空间中) - 包含的构建(无包含的构建包含此插件) - 插件仓库(无法解析插件工件 'com.android.application:com.android.application.gradle.plugin:8.5.0') 已在以下仓库中搜索: Gradle中央插件仓库
相关配置文件内容
app/build.gradle
plugins { //noinspection AndroidGradlePluginVersion id 'com.android.application' version '8.5.0' apply false id 'org.jetbrains.kotlin.android' version '1.9.22' apply false id 'dev.flutter.flutter-gradle-plugin' apply false id 'com.google.gms.google-services' version '4.4.2' apply false } def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } android { namespace 'com.example.application' compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { applicationId "appID" minSdkVersion 21 compileSdk 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName ndk { abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64' } } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } } ndkVersion '25.1.8937393' compileSdk 34 } flutter { source '../..' } }
android/build.gradle
allprojects { repositories { google() mavenCentral() gradlePluginPortal() } } rootProject.layout.buildDirectory = '../build' subprojects { project.layout.buildDirectory = "${rootProject.layout.buildDirectory}/${project.name}" project.evaluationDependsOn(":app") } subprojects { project.evaluationDependsOn(':app') } tasks.register("clean", Delete) { delete rootProject.layout.buildDirectory } subprojects { afterEvaluate { project -> if (project.hasProperty('android')) { project.android { if (namespace == null) { namespace project.group } } } } }
Gradle根设置文件(settings.gradle)
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() gradlePluginPortal() } } rootProject.name = "My Application" include ':app' project(':app').projectDir = new File(rootDir, 'company/android/app/')
android/settings.gradle
pluginManagement { def flutterSdkPath = { def properties = new Properties() file("local.properties").withInputStream { properties.load(it) } def flutterSdkPath = properties.getProperty("flutter.sdk") assert flutterSdkPath != null, "flutter.sdk not set in local.properties" return flutterSdkPath }() includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") repositories { google() mavenCentral() gradlePluginPortal() } } plugins { id 'com.android.application' version '8.5.0' id 'org.jetbrains.kotlin.android' version '1.9.22' id 'dev.flutter.flutter-gradle-plugin' id "dev.flutter.flutter-plugin-loader" id 'com.google.gms.google-services' version '4.4.2' } include ":app"
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
解决方法
1. 修复插件重复声明问题
你的配置中存在插件版本重复声明的冲突:android/settings.gradle已经统一声明了所有插件的版本,app/build.gradle无需再重复指定版本。修改app/build.gradle的plugins块:
plugins { id 'com.android.application' apply false id 'org.jetbrains.kotlin.android' apply false id 'dev.flutter.flutter-gradle-plugin' apply false id 'com.google.gms.google-services' apply false }
2. 清理语法错误
app/build.gradle末尾多了一个多余的},删除该闭合括号,避免语法解析失败。
3. 确保仓库访问正常
Android Gradle插件仅发布在Google Maven仓库,你的android/settings.gradle中已经配置了google()仓库,需确保网络可以正常访问该仓库(若有网络限制,需配置代理或镜像)。
4. 清理缓存并重新同步
- 执行Android Studio菜单:
File -> Invalidate Caches... -> Invalidate and Restart - 删除项目根目录的
.gradle文件夹和android/.gradle文件夹 - 重新执行
Gradle Sync操作
内容的提问来源于stack exchange,提问作者RiseOfHorizon
相关产品推荐
相关产品推荐

