You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 21:30:58