Flutter打包APK时AGP版本兼容及插件解析失败问题求助
解决Flutter打包APK时的AGP版本兼容与插件解析问题
问题回顾
最初打包时遇到AGP与Kotlin插件版本不兼容:
Failed to apply plugin 'kotlin-android'.
Kotlin Gradle Plugin <-> Android Gradle Plugin compatibility issue:
The applied Android Gradle Plugin version (7.3.0) is lower than the minimum supported 7.3.1.Please update the Android Gradle Plugin version to at least 7.3.1.
升级AGP到7.3.1后,出现插件无法解析的错误:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (None of the included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.3.1')
Searched in the following repositories:
MavenRepo
Gradle Central Plugin Repository
解决方案
1. 匹配Gradle与AGP版本
AGP 7.3.1要求Gradle版本至少为7.4,修改项目根目录下gradle/wrapper/gradle-wrapper.properties中的distributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
2. 确保插件仓库配置正确
检查项目根目录的settings.gradle(或settings.gradle.kts),确保仓库配置包含Google仓库且顺序正确:
Groovy 语法(settings.gradle)
pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } }
Kotlin 语法(settings.gradle.kts)
pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } }
3. 同步并清理依赖缓存
执行以下命令清理并刷新依赖:
flutter clean ./gradlew clean build --refresh-dependencies
4. 对齐Kotlin插件版本
AGP 7.3.1对应Kotlin插件版本至少为1.7.10,修改项目根目录的build.gradle(或build.gradle.kts):
Groovy 语法
plugins { id "com.android.application" version "7.3.1" apply false id "org.jetbrains.kotlin.android" version "1.7.10" apply false }
Kotlin 语法
plugins { id("com.android.application") version "7.3.1" apply false id("org.jetbrains.kotlin.android") version "1.7.10" apply false }
完成以上步骤后,重新尝试打包APK即可。
内容的提问来源于stack exchange,提问作者DolDurma
相关产品推荐
相关产品推荐

