flutter-intellij icon indicating copy to clipboard operation
flutter-intellij copied to clipboard

Flutter projects do not sync in Android Studio when using Kotlin DSL (.kts), resulting in "related Gradle project not linked" and no visible Gradle UI.

Open PJPAC opened this issue 3 days ago • 0 comments

  • Proofread after being mostly written by Gemini - DESCRIBE THE ISSUE IN DETAIL: Product and Version: Android Studio (Latest Version) & Flutter (Channel stable, 3.38.3) Symptoms: • When opening a Flutter project, the android module is not recognized as a Gradle project. • A banner appears on build.gradle.kts and settings.gradle.kts files stating: "Code insight unavailable (related Gradle project not linked)". • The "Sync Project with Gradle Files" action is missing from the File menu and the main toolbar (no elephant icon). • The "Gradle" tool window does not show the project structure. • This issue occurs even on a brand new project created with flutter create --android-language kotlin. • Running ./gradlew tasks from the android directory fails with plugin resolution errors, specifically dev.flutter.flutter-plugin-loader not being found, indicating a fundamental configuration issue that precedes dependency resolution.

Environment: [√] Flutter (Channel stable, 3.38.3, on Microsoft Windows [Version 10.0.19045.6466], locale en-GB) • Flutter version 3.38.3 on channel stable at C:\dev\flutter • Framework revision 19074d12f7 • Engine revision 13e658725d • Dart version 3.10.1 [√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) • Android SDK at C:...\AppData\Local\Android\sdk • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72) • All Android licenses accepted. [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.4) [√] Connected device (1 available) [√] Network resources

Problem Analysis: The project's Gradle configuration seems to be in a state of fundamental conflict that prevents Android Studio from parsing and linking the project. The core issue appears to stem from a conflict between two different methods of integrating the Flutter framework into the Gradle build:

  1. The Legacy includeBuild Method: The settings.gradle.kts uses includeBuild to directly inject Flutter's Gradle scripts.
  2. The Modern plugin-loader Method: The settings.gradle.kts also declares id("dev.flutter.flutter-plugin-loader"). These two mechanisms are likely conflicting at a very early stage of Gradle's initialization, causing a silent but total failure. This prevents the IDE from ever recognizing the project structure, leading to the missing UI and "project not linked" state. Attempts to fix this with isolated, line-by-line changes have proven ineffective, confirming that a holistic review of the conflicting build logic is required.

Another way of looking at it is that because the issue already appears with a freshly reinstalled Otter Android Studio and the command " flutter create --android-language kotlin new_test_project " directly written on the terminal... the "Code insight unavailable (related Gradle project not linked)" warning is a very fundamental issue of (at least) the last Android Studio version when using kotlin instead of groovy files. Note that clicking on "Link Gradle Project" does not help as saving the file in the initial folder leads to "C:/Users/.../settings.gradle.kts The filename is not valid." and does not say where the file could be saved. See also https://github.com/flutter/flutter/issues/170971, https://github.com/flutter/flutter/issues/169469, https://discuss.gradle.org/t/how-do-i-fix-code-insight-is-unavailable-script-configuration-wasnt-received/49782

STEPS TO REPRODUCE:

  1. Create a new Flutter project with Kotlin DSL.
  2. Check if you don't already have the problem through steps 3 & 4, and then replace the contents of android/settings.gradle.kts and android/app/build.gradle.kts with the attached files.
  3. Open the root folder of the Flutter project in Android Studio.
  4. Observe that the Android module is not linked and no Gradle sync options are available.

Studio Build: Android Studio Otter 2 Feature Drop | 2025.2.2 / Build #AI-252.27397.103.2522.14514259, built on December 1, 2025 / Runtime version: 21.0.8+-14196175-b1038.72 amd64 / VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Version of Gradle Plugin: bundled 252.27397.103.2522.14514259 Version of Gradle: in gradle-wrapper.properties I use distributionUrl=https://services.gradle.org/distributions/gradle-8.12-all.zip NB regarding Gradle - in Settings > Build, Execution, Deployment > Build Tools > Gradle there is no drop-down menu and I can only read "Select configuration element in the tree to edit its settings". The tree being referred to is rather unclear to me and does not allow editing any settings. Version of Java: there is an uncertainty between JavaVersion.VERSION_17 from android/app/build.gradle.kts and "Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)" from gradlew OS: Windows 10

android_build.gradle.kts.txt android_setting.gradle.kts.txt app_build.gradle.kts.txt

PJPAC avatar Dec 10 '25 08:12 PJPAC