Flutter打包Android App Bundle报错:com.android.application插件未找到
解决Flutter打包App Bundle时‘Plugin with id 'com.android.application' not found’错误
核心排查与修复步骤
1. 核对build.gradle配置完整性
- 项目根目录build.gradle:必须配置Android Gradle插件的仓库和依赖,示例如下:
buildscript { ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:7.4.2" // 替换为对应兼容版本 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.15' // Firebase依赖需保留 } } allprojects { repositories { google() mavenCentral() } } - android/app/build.gradle:开头必须声明应用插件,两种写法二选一:
// 旧写法 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'dev.flutter.flutter-gradle-plugin' apply plugin: 'com.google.gms.google-services' // 新写法(Gradle 7+推荐) plugins { id 'com.android.application' id 'kotlin-android' id 'dev.flutter.flutter-gradle-plugin' id 'com.google.gms.google-services' }
2. 确保Gradle与插件版本匹配
打开android/gradle/wrapper/gradle-wrapper.properties,检查distributionUrl对应的Gradle版本,必须和Android Gradle插件版本兼容:
// 示例:插件7.4.2对应Gradle 7.5 distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
(版本对应关系可参考Android Studio内置的Gradle插件提示,避免跨版本不兼容)
3. 清理缓存并重新构建
- 执行
flutter clean清理Flutter缓存 - 删除
android/.gradle目录(注意不是全局~/.gradle) - 重新运行
flutter build appbundle
4. 验证Android环境完整性
执行flutter doctor,确认Android SDK Build Tools、Android SDK Platform、Gradle等组件均已正确安装,无红色警告。
5. 检查Firebase配置
确保google-services.json已放置在android/app目录下,且build.gradle中正确引入了google-services插件(如上述配置所示)。
报错信息示例:
* What went wrong: A problem occurred evaluating project ':app'. > Plugin with id 'com.android.application' not found.
内容的提问来源于stack exchange,提问作者Nissaba
相关产品推荐
相关产品推荐

