升级Flutter后Android应用构建失败求助
Flutter Android构建错误:Could not get unknown property 'flutter' for extension 'android'
环境信息
- Flutter版本:3.29.2
- google_maps_flutter版本:2.12.1
报错详情
FAILURE: Build failed with an exception. * Where: Build file 'C:\Users\AlSaFFaR\AppData\Local\Pub\Cache\hosted\pub.dev\google_maps_flutter_android-2.16.0\android\build.gradle' line: 26 * What went wrong: A problem occurred evaluating project ':google_maps_flutter_android'. > Could not get unknown property 'flutter' for extension 'android' of type com.android.build.gradle.LibraryExtension. * 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 2s Error: Gradle task assembleDebug failed with exit code 1
解决方案
1. 强制指定兼容的google_maps_flutter_android版本
在项目根目录的pubspec.yaml中添加dependency_overrides,锁定与你的google_maps_flutter版本匹配的Android端依赖版本:
dependency_overrides: google_maps_flutter_android: 2.15.0
执行命令更新依赖:
flutter pub get
2. 彻底清理缓存并重新构建
执行以下命令清除旧缓存和构建文件,再重新编译:
flutter clean flutter pub cache clean flutter pub get flutter run
原理说明
你当前使用的google_maps_flutter 2.12.1与自动拉取的google_maps_flutter_android 2.16.0存在版本不兼容问题,后者的Gradle配置依赖更高版本的Flutter Gradle插件特性,而你的环境无法满足。通过锁定兼容的Android端依赖版本,可以解决该属性找不到的错误。
内容的提问来源于stack exchange,提问作者Hussain AL-saffar
相关产品推荐
相关产品推荐

