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

含Git子模块的Flutter项目在Android Studio中无法识别Dart文件

Flutter项目Git子模块在Android Studio中Dart文件无法识别的问题

问题描述

我有一个包含Git子模块的Flutter项目,在Android Studio中打开时,Dart文件无法被识别。该问题在Android Studio Ladybug和Koala多个版本中均会出现。

复现步骤

  1. 在Android Studio中打开带有子模块的Flutter项目。
  2. Dart文件不被识别,语法高亮、自动补全和代码分析功能失效。
  3. 尝试解决:先禁用项目的Dart支持,仅为主模块启用Dart支持。
  4. 这会强制Android Studio重新分析Flutter项目。
  5. 随后为子模块启用Dart支持。
  6. 问题再次出现——Dart文件又无法被识别。
  7. 重启Android Studio有时会随机触发同一问题。

环境信息

  • Android Studio Ladybug & Koala(已测试多个版本)
  • Flutter(已测试最新及旧版本)
  • Dart(已测试最新及旧版本)

flutter-doctor 输出

C:\Users\***>flutter doctor -v
[√] Flutter (Channel stable, 3.27.3, on Microsoft Windows [Version 10.0.22631.4751], locale en-US)
    • Flutter version 3.27.3 on channel stable at C:\Users\***\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (2 weeks ago), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    • Android SDK at C:\Users\***\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: C:\Users\***\AppData\Local\Programs\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Users\***\AppData\Local\Programs\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 15 (API 35) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22631.4751]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 132.0.6834.160
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 132.0.2957.115

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

已尝试方案

  • 升级/降级Flutter → 无效果。
  • 升级/降级Android Studio → 无效果。
  • 重新安装Flutter和Android Studio → 无效果
  • 重新安装Flutter和Dart插件 → 无效果
  • 删除项目后重新拉取 → 无效果
  • 在Dart分析设置中启用“Scope Analysis to Current Package” → 无效果。
  • 创建全新Flutter项目 → 可正常运行,说明问题仅针对含子模块的项目。

问题咨询

请问是否有人遇到过Android Studio中Flutter子模块的此类问题?有没有可靠的方法能确保Dart文件始终被正确识别,无需手动反复禁用和启用Dart支持?


内容的提问来源于stack exchange,提问作者suprim

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 13:32:05