Flutter构建报错:Plugin [id: 'kotlin-android'] was not found 求助
Flutter构建报错:找不到
kotlin-android插件 报错信息
FAILURE: Build failed with an exception. * Where: Build file 'C:\Users\MOTAP ERP\StudioProjects\restaurant\android\app\build.gradle' line: 3 * What went wrong: Plugin [id: 'kotlin-android'] was not found in any of the following sources: - Gradle Core Plugins (not a core plugin) - Included Builds (None of the included builds contain this plugin) - Plugin Repositories (plugin dependency must include a version number for this source) * Try: > Run with --stacktrace option to get the stack trace. > 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 BUILD FAILED in 877ms Exception: Gradle task assembleDebug failed with exit code 1
已确认Kotlin插件已安装,尝试过常规方案无效,附上相关配置文件:
app/build.gradle 原内容
plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } } flutter { source '../..' } dependencies { implementation 'androidx.multidex:multidex:2.0.1' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }
android/build.gradle 原内容
buildscript { ext.kotlin_version = "1.7.10" repositories { google() mavenCentral() dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() } }
问题分析与解决
从配置文件看,核心问题是Gradle配置文件存在语法结构错误,导致插件无法被正确识别加载:
1. 修正 android/build.gradle
原文件中dependencies块被错误嵌套在repositories块内部,调整结构并补充必要的Android Gradle插件依赖:
buildscript { ext.kotlin_version = "1.7.10" repositories { google() mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.android.tools.build:gradle:7.4.2" // 版本需与本地Gradle匹配,可按需调整 } } allprojects { repositories { google() mavenCentral() } }
2. 修正 app/build.gradle
原文件缺失android代码块,且多了一个多余的闭合},调整后:
plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" } android { kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } } flutter { source '../..' } dependencies { implementation 'androidx.multidex:multidex:2.0.1' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }
后续操作
- 检查Android Studio的Kotlin插件版本是否与配置中
kotlin_version(1.7.10)匹配,可在File > Settings > Plugins > Kotlin查看 - 执行
flutter clean清除缓存,再重新运行flutter run
内容的提问来源于stack exchange,提问作者fcozsargin
相关产品推荐
相关产品推荐

