Flutter项目Gradle构建失败:找不到Properties()方法求助
解决Flutter项目Gradle构建失败:Could not find method Properties()
错误信息
FAILURE: Build failed with an exception. * Where: Build file 'E:\new epads\epads-ppra-epads.mobileapplication.flutter-c9460f2b2f3c\android\app\build.gradle' line: 1 * What went wrong: A problem occurred evaluating project ':app'. > Could not find method Properties() for arguments [] on project ':app' of type org.gradle.api.Project. * 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 1s
解决方案
修正app/build.gradle语法
打开android/app/build.gradle,把第一行的def localProperties = Properties()改成def localProperties = new Properties()。Gradle 7.x及以上版本不再默认导入java.util.Properties,必须显式用new关键字实例化。匹配Gradle与Flutter版本
Flutter 3.3.0推荐搭配Gradle 7.4.2,修改android/gradle/wrapper/gradle-wrapper.properties里的distributionUrl:distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip同步Android Gradle Plugin版本
打开android/build.gradle,在buildscript -> dependencies下,将Android Gradle Plugin版本改为7.4.2(与Gradle版本匹配):classpath 'com.android.tools.build:gradle:7.4.2'清理缓存重新构建
执行命令清理缓存:flutter clean手动删除
android/.gradle文件夹,再运行flutter run重新构建项目。
内容的提问来源于stack exchange,提问作者Waheed Ullah
相关产品推荐
相关产品推荐

