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

Flutter项目android/app/build.gradle报Cannot resolve symbol GradleException错误

解决方案

  1. 处理Cannot resolve symbol 'GradleException'报错
    将android/app/build.gradle中抛出GradleException的代码:
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")

替换为:

throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")

新版Gradle中默认不再直接暴露GradleException,用Java内置的FileNotFoundException完全可以实现相同的异常抛出逻辑,也是目前Flutter官方模板的修改方案。

  1. 处理Cannot resolve symbol 'Properties'、Cannot resolve symbol 'File'报错
    在所有提示这类错误的gradle文件(包括android/app/build.gradle、android/settings.gradle)最顶部添加以下导入语句:
import java.io.File
import java.util.Properties
  1. 清理IDE缓存消除残留误报
    如果完成上述修改后IDE仍然有红线提示,执行以下操作:
  • 点击Android Studio顶部菜单栏 File > Invalidate Caches
  • 勾选Clear file system cache and local history选项,点击Invalidate and Restart
  • 等待IDE重启完成、索引加载结束后,报错提示就会完全消失

注意:部分Arctic Fox版本的Android Studio存在Gradle语法检查的已知bug,只要执行flutter run或flutter build apk能正常编译运行,即使有少量红线提示也不会影响实际使用。

内容的提问来源于stack exchange,提问作者D. Joe

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 08:36:05