leoafarias / fvm

Flutter Version Management: A simple CLI to manage Flutter SDK versions.
https://fvm.app
MIT License
4.44k stars 213 forks source link

[BUG] `flutter` still not same with `fvm flutter` (fvm 3.0.0) #599

Open husainazkas opened 4 months ago

husainazkas commented 4 months ago

Describe the bug I've read your release changelog for this version which at first point it says fvm will automatically configure VSCode to use the correct Flutter SDK version. So I just need to type flutter instead of fvm flutter. The problem is it's not like you describe.

To Reproduce Steps to reproduce the behavior:

  1. Open terminal and make sure you have at least 2 versions (this case uses stable and 3.13.9)
  2. Set global version to stable (just to make sure)
  3. Go to project directory which need to use 3.13.9 and run fvm use 3.13.9
  4. Restart/reopen terminal on project directory
  5. Run flutter --version, you will see Flutter SDK version from global
  6. Run fvm flutter --version, you will see Flutter SDK version from current project

Expected behavior As you describe in changelog, I hope whatever version I use in different project will use correct SDK version, except has not configured with specific version

Logs

  1. Set global to stable (3.16.9)
    
    > fvm global --verbose
    Argument information:
    Top level options:
    - verbose: true

Command: global

✔ Select a version: · stable

Default in path: true Cached version in path: false Pinned version in path: false

flutterInPath: /Users/husainazkas/fvm/default/bin ctx.globalCacheBinPath: /Users/husainazkas/fvm/default/bin cacheVersion.binPath: /Users/husainazkas/fvm/versions/stable/bin pinnedCacheVersion?.binPath: /Users/husainazkas/fvm/versions/3.13.9/bin

Flutter SDK: Channel: Stable is now global


2. Set current project to 3.13.9
```zsh
> fvm use 3.13.9 --verbose
Argument information:
  Top level options:
  - verbose: true

Command: use

Updating project config
Project name: flutter_project
Project path: /Users/husainazkas/path/to/project/flutter_project

Checking .gitignore
Update gitignore: true
.fvm/ already exists in .gitignore
✓ Project now uses Flutter SDK : SDK Version : 3.13.9
  1. Show flutter version at current project

    > flutter --version
    Flutter 3.16.9 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision 41456452f2 (3 weeks ago) • 2024-01-25 10:06:23 -0800
    Engine • revision f40e976bed
    Tools • Dart 3.2.6 • DevTools 2.28.5
  2. Show fvm flutter version at current project

    > fvm flutter --version
    Flutter 3.13.9 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision d211f42860 (4 months ago) • 2023-10-25 13:42:25 -0700
    Engine • revision 0545f8705d
    Tools • Dart 3.1.5 • DevTools 2.25.0
  3. Run fvm doctor at current project

    
    > fvm doctor

FVM Doctor:

Project: ┌─────────────────────────────┬────────────────────────────────────────────────────────────┐ │ Project │ flutter_project │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Directory │ /Users/husainazkas/path/to/project/flutter_project │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Active Flavor │ None │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Is Flutter Project │ Yes │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Dart Tool Generator Version │ 3.1.5 │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Dart tool version │ 3.13.9 │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ .gitignore Present │ Yes │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Config Present │ Yes │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Pinned Version │ 3.13.9 │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Config path │ .fvmrc │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Local cache dir │ .fvm/versions │ ├─────────────────────────────┼────────────────────────────────────────────────────────────┤ │ Version symlink │ .fvm/versions/3.13.9 │ └─────────────────────────────┴────────────────────────────────────────────────────────────┘

IDEs: ┌────────────────────────────────┬────────────────────────────────────────┐ │ IDEs │ Value │ ├────────────────────────────────┼────────────────────────────────────────┤ │ VSCode │ │ ├────────────────────────────────┼────────────────────────────────────────┤ │ dart.flutterSdkPath │ .fvm/versions/3.13.9 │ ├────────────────────────────────┼────────────────────────────────────────┤ │ Matches pinned version: │ true │ ├────────────────────────────────┼────────────────────────────────────────┤ │ IntelliJ (Android Studio, ...) │ │ ├────────────────────────────────┼────────────────────────────────────────┤ │ flutter.sdk │ /Users/husainazkas/fvm/versions/3.13.9 │ ├────────────────────────────────┼────────────────────────────────────────┤ │ Matches pinned version: │ true │ ├────────────────────────────────┼────────────────────────────────────────┤ │ IntelliJ (Android Studio, ...) │ No .idea folder found │ └────────────────────────────────┴────────────────────────────────────────┘

Environment: ┌───────────────────────┬────────────────────────────────────────────┐ │ Environment Variables │ Value │ ├───────────────────────┼────────────────────────────────────────────┤ │ Flutter PATH │ /Users/husainazkas/fvm/default/bin/flutter │ ├───────────────────────┼────────────────────────────────────────────┤ │ Dart PATH │ /usr/local/bin/dart │ ├───────────────────────┼────────────────────────────────────────────┤ │ FVM_CACHE_PATH │ N/A │ ├───────────────────────┼────────────────────────────────────────────┤ │ FVM_GIT_CACHE │ N/A │ ├───────────────────────┼────────────────────────────────────────────┤ │ FVM_GIT_CACHE_PATH │ N/A │ ├───────────────────────┼────────────────────────────────────────────┤ │ FVM_FLUTTER_URL │ N/A │ ├───────────────────────┼────────────────────────────────────────────┤ │ Flutter PATH │ /Users/husainazkas/fvm/default/bin/flutter │ ├───────────────────────┼────────────────────────────────────────────┤ │ Dart PATH │ /usr/local/bin/dart │ └───────────────────────┴────────────────────────────────────────────┘ ┌──────────────┬────────────────────────────────────────────────────────────────┐ │ Platform │ Value │ ├──────────────┼────────────────────────────────────────────────────────────────┤ │ OS │ macos Version 14.3.1 (Build 23D60) │ ├──────────────┼────────────────────────────────────────────────────────────────┤ │ Dart Locale │ en-ID │ ├──────────────┼────────────────────────────────────────────────────────────────┤ │ Dart runtime │ 3.2.6 (stable) (Wed Jan 24 13:41:58 2024 +0000) on "macos_x64" │ └──────────────┴────────────────────────────────────────────────────────────────┘



- FVM Version 3.0.0
leoafarias commented 4 months ago

@husainazkas, after you use the version the terminal should indicate that the PATH has changed. Like this video. Can you review and make sure that this is happening? https://github.com/leoafarias/fvm/assets/435833/d284b8f8-2bff-404e-bde6-34c8c7b7fc3c

husainazkas commented 4 months ago

Sorry there is a missing step on reproduce. Actually I always make myself to very clearly sure that any changes affected by reopen terminal & vscode directly, ofcourse when vscode reopened it will continue last terminal then I always kill & open new terminal. But no luck, it still read global version because of PATH on my .zshrc referred to ~/fvm/default/bin/flutter.

husainazkas commented 4 months ago

And also if you look at my fvm doctor you can see the flutter version and dart version is not match, I know I have to make another github issue but I'll do it later

leoafarias commented 4 months ago

@husainazkas interesting, there is a settings flag called addSdkToTerminalPath. Can you also confirm that this is set to true?

husainazkas commented 4 months ago

ofcourse it's set to true

husainazkas commented 4 months ago

any updates? @leoafarias

leoafarias commented 4 months ago

I was not able to replicate.

Can you do "which flutter" on the vscode terminal and send the output here?

husainazkas commented 4 months ago

I think I found possibility reason why this bug happened.

Previously, I have set below env to my .zshrc:

export PATH=$HOME/fvm/default/bin:$PATH

It means global version has been set on user-level env. So If I open vscode that use different flutter version and call flutter instead of fvm flutter it will refer to my .zshrc config and show wrong version, not as described in 3.0.0 release note.

But if that flutter global version is not set on .zshrc, I can call flutter in a flutter project with correct version sdk.

Ofcouse I cannot call flutter outside flutter project because zsh will not know that command. To fix this we can set aliases through .zshrc like this:

alias flutter="fvm flutter"
alias dart="fvm dart"

My analysis still not fix whole problem, it leaves one more problem. The problem is vscode extension still have weird env config (Idk why) when you call command palette Run flutter doctor, the output will have warning flutter path like this:

[flutter] flutter doctor -v
[!] Flutter (Channel stable, 3.13.9, on macOS 14.3.1 23D60 darwin-x64, locale en-ID)
    • Flutter version 3.13.9 on channel stable at /Users/husainazkas/fvm/versions/3.13.9
    ! Warning: `flutter` on your path resolves to /Users/husainazkas/fvm/versions/stable/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/husainazkas/fvm/versions/3.13.9. Consider adding /Users/husainazkas/fvm/versions/3.13.9/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/husainazkas/fvm/versions/stable/bin/dart, which is not inside your current Flutter SDK checkout at /Users/husainazkas/fvm/versions/3.13.9. Consider adding /Users/husainazkas/fvm/versions/3.13.9/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (4 months ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/husainazkas/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/husainazkas/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
    • android-studio-dir = /Applications/Android Studio.app
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.86.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.82.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 14.3.1 23D60 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.119
    ! Error: Browsing on the local area network for My iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

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

! Doctor found issues in 1 category.
exit code 0
husainazkas commented 4 months ago

I was not able to replicate.

Can you do "which flutter" on the vscode terminal and send the output here?

After my fix above, it has succeed show correct output (not sure but at least correct version):

> which flutter
/Users/husainazkas/fvm/versions/3.13.9/bin//flutter
leoafarias commented 4 months ago

I would suggest against doing this. This is a bit weird as I believe dart code extension adds priority over the PATH. But will confirm.

One last questions do you have the env FLUTTER_ROOT configured anywhere?

husainazkas commented 4 months ago

nope

wongcheehong commented 2 months ago

I have encounter this issue also with FVM 3.1.4. Interestingly, I am able to setup one project without problem, but the second project I setup got this issue.

wongcheehong commented 2 months ago

I have encounter this issue also with FVM 3.1.4. Interestingly, I am able to setup one project without problem, but the second project I setup got this issue.

I got it fix by reinstall the VS Code's Flutter & Dart extension

masreplay commented 1 month ago

Remove all flutter variables then add this (export all flutter versions to the path)

# FLUTTER
for dir in $HOME/fvm/versions/*; do
  if [ -d "$dir" ]; then
    export PATH="$dir/bin:$PATH"
  fi
done

export PATH="$HOME/fvm/default/bin:$PATH"
export PATH="$HOME/.pub-cache/bin:$PATH"

alias flutter="fvm flutter"
alias dart="fvm dart"

Kill the terminal, and Vscode then open them again

JaviGaiax commented 1 month ago

Same issue here. Sometimes I just simply change SDKs to another one or change to another project and then for no reason flutter doctor and fvm flutter doctor will stop giving the same output.

leoafarias commented 1 month ago

The vscode integration needs to happen within the vscode terminal for the behavior to be correct.

When running a project-configured flutter sdk outside of vscode, you still have to proxy or create an alias that points to the project symlink.

JaviGaiax commented 1 month ago

I'm doing everything through the vscode terminal and fvm though so no weird actions on my part there. edit: Did a whole flutter and fvm clean install and the problem persists.

Peetee06 commented 3 weeks ago

I faced the same issue. I added fvm to the beginning of PATH like this export PATH=$HOME/fvm/default/bin:$PATH in my .zshrc. Changed it to be appended to the end like this: export PATH=$PATH:$HOME/fvm/default/bin. And then it worked. I also needed to set "dart.addSdkToTerminalPath": true