执行flutter build appbundle时遇localProperties属性未知错误求助
解决Gradle构建错误:Could not get unknown property 'localProperties' for project ':app'
问题原因
代码中直接调用了localProperties变量,但该变量未被定义和加载,Gradle无法识别它。
解决方案
在使用localProperties之前,先添加代码加载local.properties文件:
修改后的android/app/build.gradle代码片段:
// 先加载local.properties文件 def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localProperties.load(new FileInputStream(localPropertiesFile)) } def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") }
额外检查
- 确认项目根目录(与android文件夹同级)存在
local.properties文件,文件内包含flutter.sdk=你的Flutter SDK路径 - 若
local.properties不存在,可手动创建,或执行flutter doctor命令让Flutter自动生成该文件
内容的提问来源于stack exchange,提问作者Mahender Kumar
相关产品推荐
相关产品推荐

