flutter / flutter-intellij

Flutter Plugin for IntelliJ
https://flutter.dev/using-ide
BSD 3-Clause "New" or "Revised" License
1.98k stars 318 forks source link

Relax Flutter SDK validation in the settings field #4513

Open gspencergoog opened 4 years ago

gspencergoog commented 4 years ago

Steps to Reproduce

When I open the Flutter framework to work on it, the "No Flutter SDK Configured" banner keeps reappearing.

1) Open the Flutter framework in the IDE 2) see the "No Flutter SDK Configured" banner at the top of a Dart file. 3) Click on "Open Flutter Settings" 4) Select your flutter directory. 5) Wait until the version information populates. Mine says:

Flutter 1.18.0-9.0.pre.33 • channel ignore_focus • git@github.com:gspencergoog/flutter.git
Framework • revision dc6c453262 (6 hours ago) • 2020-04-27 11:40:08 -0700
Engine • revision 4bcfae82c7
Tools • Dart 2.9.0 (build 2.9.0-3.0.dev a69cb6d700)

6) Click "Apply" 7) Notice that the selected flutter SDK field blanks out again 8) Select the flutter directory again 5) Wait until the version information populates again. 9) Click "OK". 10) Notice that: a) The banner didn't go away b) When I reopen the settings page, the SDK path is blank again. c) Even if I click "dismiss", closing the tab and reopening that file brings back the banner.

no_flutter_sdk

Version info

I also do have IntelliJ installed, just not in a standard location that flutter doctor can find it in. I'm running IntelliJ CE 2020.1, with the 46.0.3-dev.3 version of the Flutter plugin.

[✓] Flutter (Channel ignore_focus, v1.18.0-9.0.pre.33, on Mac OS X 10.15.4
    19E287, locale en-US)
    • Flutter version 1.18.0-9.0.pre.33 at /Users/gspencer/code/flutter
    • Framework revision dc6c453262 (6 hours ago), 2020-04-27 11:40:08 -0700
    • Engine revision 4bcfae82c7
    • Dart version 2.9.0 (build 2.9.0-3.0.dev a69cb6d700)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/gspencer/Library/Android/sdk
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /Users/gspencer/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.9.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 38.2.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build
      1.8.0_202-release-1483-b49-5587405)

[!] VS Code (version 1.43.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    ✗ Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • macOS      • macOS      • darwin-x64     • Mac OS X 10.15.4 19E287
    • Web Server • web-server • web-javascript • Flutter Tools
    • Chrome     • chrome     • web-javascript • Google Chrome 81.0.4044.122
devoncarew commented 4 years ago

Hmm, I'm not sure what's going on here.

Can you set the Dart sdk from the Dart settings page? Under the good, the Flutter settings page just sets the dart sdk to the one in /bin/cache/dart-sdk.

Have you tried File > Invalidate Caches / Restart? That can often address strange IntelliJ issues.

devoncarew commented 4 years ago

What do you see in the project's .idea/libraries/Dart_SDK.xml file?

gspencergoog commented 4 years ago

Invalidating the cache and restarted helped, at least for a few days.

I'm seeing the problem again now, though. The Dart SDK appears to be set correctly in the Dart plugin settings. It says support is enabled, and the SDK path is /Users/gspencer/code/flutter/bin/cache/dart-sdk, which is correct. The SDK path in the Flutter plugin is blank, and while I can set it, pressing Apply or OK clears it again (as before).

I've archived my .idea directory for you if you want it. Are there any other caches/locations I should preserve for debugging?

The Dart_SDK.xml file contains this, which all looks pretty normal to me.

<component name="libraryTable">
  <library name="Dart SDK">
    <CLASSES>
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/async" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/cli" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/collection" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/convert" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/core" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/developer" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/ffi" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/html" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/indexed_db" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/io" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/isolate" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/js" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/js_util" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/math" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/mirrors" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/svg" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/typed_data" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/wasm" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/web_audio" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/web_gl" />
      <root url="file://$PROJECT_DIR$/bin/cache/dart-sdk/lib/web_sql" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</component>
devoncarew commented 4 years ago

Interesting. It's possible that we don't think that the sdk you're entering in is a valid Flutter sdk. Is there anything unique about the sdk you're using?

I'm guessing that you're working on code in the flutter repo itself, and the sdk path is effectively relative to the project you're working on (that's a supported use case, I just want to confirm)?

gspencergoog commented 4 years ago

Yes, that's how it is configured. The SDK isn't anything special, it's the one downloaded by the Flutter tool.

About the only thing I can think of is that I do have my cache directory symlinked (so bin/cache is a symlink to bin/cache.master in that same directory). This is so I can avoid downloading another Gig of data each time I switch to stable/dev and back to master.

I was going to try quitting IntelliJ, switching to a non-symlinked cache dir, and starting again, but I simply restarted (without invalidating the IntelliJ cache, or changing the symlink), and the problem went away: the Flutter plugin now shows the right SDK setting.

So, it's possible that having my Flutter cache dir symlinked could cause some issues, but I don't think I moved the symlink around while IntelliJ was running, and it should follow links, right?

gspencergoog commented 4 years ago

OK, I've removed the symlink (just installed entirely separate flutter SDKs for stable, beta, and dev), and restarted IntelliJ again, and I'll keep a watch out for it happening again.

devoncarew commented 4 years ago

I suspect it was the symlink - that we couldn't validate the flutter sdk because we didn't see the dart sdk.

We should likely either relax the validation or handle symlinks (assuming that was the issue).

gspencergoog commented 4 years ago

OK, I just had this happen again, and this time I don't have any symlinks at all. Identical symptoms. I tarred up my entire Flutter repo if you want it.

This time it started happening just after a "Clear cache and restart".

gspencergoog commented 4 years ago

Some notes of things Devon and I tried while debugging this. 1) I sent him the .idea directory from my project. 2) I sent him the idea.log file.

He found the following stack trace in it, leading him to think that the problem could be my settings repository auto-sync changing the settings under the plugin.

java.lang.InterruptedException
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:78)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
    at org.jetbrains.settingsRepository.AutoSyncManager$autoSync$3.run(autoSync.kt:102)
    at com.intellij.util.RunnableCallable.call(RunnableCallable.java:20)
    at com.intellij.util.RunnableCallable.call(RunnableCallable.java:11)
    at com.intellij.openapi.application.impl.ApplicationImpl$1.call(ApplicationImpl.java:255)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

I turned off auto-sync, and restarted and cleared the cache, and I'm back to the non-broken state again, but that has happened before.

I'm going to keep using it and if it breaks again, we'll take another look.

stevemessick commented 4 years ago

@gspencergoog Did you set a custom location in File > Settings Repository...:

Screen Shot 2020-05-21 at 2 28 57 PM

I'm just looking for a repro case.

gspencergoog commented 4 years ago

Yes, it's set to my private settings repository (I skip around between machines a lot, and I need to have it synced on multiple machines to stay sane).