Flutter项目build.gradle文件编译失败问题求助
Flutter Multidex构建失败:compileSdkVersion方法错误解决
错误日志
Building with Flutter multidex support enabled. FAILURE: Build failed with an exception. * Where: Build file '/home/bless/Documents/myprojects/HikersAfrique/android/app/build.gradle' line: 30 * What went wrong: A problem occurred evaluating project ':app'. > Could not find method compileSdkVersion() for arguments [extension 'flutter'] on extension 'android' of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension. * 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 45s Running Gradle task 'assembleRelease'... 46.4s Gradle task assembleRelease failed with exit code 1
问题原因
错误出在android/app/build.gradle第30行,你错误地将compileSdkVersion写成了方法调用形式(传入flutter作为参数),但正确写法应该是读取Flutter扩展中定义的compileSdkVersion属性值。
解决步骤
- 打开
android/app/build.gradle文件,定位到第30行 - 将错误代码(类似
compileSdkVersion(flutter))修改为:compileSdkVersion flutter.compileSdkVersion - 同步检查
minSdkVersion、targetSdkVersion是否存在同样错误写法,如有一并修正为:minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion - 执行
flutter clean清理缓存,再重新运行flutter build apk --release构建命令
额外注意
确保android/build.gradle中的Gradle插件版本与当前Flutter版本兼容,比如Flutter 3.10及以上版本,建议使用Gradle插件7.4.2及以上版本。
内容的提问来源于stack exchange,提问作者njogubless
相关产品推荐
相关产品推荐

