flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.74k stars 27.63k forks source link

Flutter doctor uses wrong path to determine the Java version: Cannot execute /wrong/path/to/java to determine the version. #108618

Open jfsanchez91 opened 2 years ago

jfsanchez91 commented 2 years ago

I installed flutter using snap $ sudo snap install flutter --classic

Here is my environment:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Neon
Description:    KDE neon User - 5.25
Release:        20.04
Codename:       focal
$ arch 
x86_64
$ echo $JAVA_HOME
/home/USER/.sdkman/candidates/java/8.332.08.1-amzn
$ sdk current java 
Using java version 8.332.08.1-amzn
$ which java
/home/USER/.sdkman/candidates/java/8.332.08.1-amzn/bin/java
$ java -version
openjdk version "1.8.0_332"
OpenJDK Runtime Environment Corretto-8.332.08.1 (build 1.8.0_332-b08)
OpenJDK 64-Bit Server VM Corretto-8.332.08.1 (build 25.332-b08, mixed mode)

Here is the flutter doctor -v report:

[✓] Flutter (Channel stable, 3.0.5, on KDE neon User - 5.25 5.15.0-41-generic, locale en_US.UTF-8)
    • Flutter version 3.0.5 at /home/USER/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (2 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /home/USER/Databank/Android/Sdk/
    • Platform android-32, build-tools 30.0.2
    • Java binary at: /home/USER/.sdkman/candidates/java/8.0.222-amzn/bin/java
    ✗ Cannot execute /home/USER/.sdkman/candidates/java/8.0.222-amzn/bin/java to determine the version

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    • cmake version 3.10.2
    • ninja version 1.8.2
    • pkg-config version 0.29.1

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2022.1)
    • IntelliJ at /home/USER/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/221.6008.13
    • 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

[✓] VS Code (version 1.69.2)
    • VS Code at /usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • KDE neon User - 5.25 5.15.0-41-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 103.0.5060.134

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.

How can I solve the java verion error "Cannot execute /home/USER/.sdkman/candidates/java/8.0.222-amzn/bin/java to determine the version" reported? I don't even have that java version (8.0.222-amzn) installed in my system

$ sdk list java
================================================================================
Available Java Versions for Linux 64bit
================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Corretto      |     | 18.0.2       | amzn    |            | 18.0.2-amzn         
               |     | 18.0.1       | amzn    |            | 18.0.1-amzn         
               |     | 17.0.4       | amzn    |            | 17.0.4-amzn         
               |     | 17.0.3.6.1   | amzn    | installed  | 17.0.3.6.1-amzn     
               |     | 17.0.0.35.1  | amzn    |            | 17.0.0.35.1-amzn    
               |     | 11.0.16      | amzn    |            | 11.0.16-amzn        
               |     | 11.0.15.9.1  | amzn    | installed  | 11.0.15.9.1-amzn    
               |     | 11.0.12.7.1  | amzn    |            | 11.0.12.7.1-amzn    
               | >>> | 8.332.08.1   | amzn    | installed  | 8.332.08.1-amzn     
               |     | 8.0.342      | amzn    |            | 8.0.342-amzn        
 Dragonwell    |     | 17.0.3       | albba   |            | 17.0.3-albba        
               |     | 11.0.15      | albba   |            | 11.0.15-albba       
               |     | 11.0.12.8    | albba   |            | 11.0.12.8-albba     
               |     | 8.8.9        | albba   |            | 8.8.9-albba         
               |     | 8.0.332      | albba   |            | 8.0.332-albba       
 Gluon         |     | 22.1.0.1.r17 | gln     |            | 22.1.0.1.r17-gln    
               |     | 22.1.0.1.r11 | gln     |            | 22.1.0.1.r11-gln    
 GraalVM       |     | 22.1.0.r17   | grl     | installed  | 22.1.0.r17-grl      
               |     | 22.1.0.r11   | grl     |            | 22.1.0.r11-grl      
               |     | 22.0.0.2.r17 | grl     |            | 22.0.0.2.r17-grl    
               |     | 22.0.0.2.r11 | grl     |            | 22.0.0.2.r11-grl    
               |     | 21.3.2.r17   | grl     |            | 21.3.2.r17-grl      
               |     | 21.3.2.r11   | grl     |            | 21.3.2.r11-grl      
               |     | 21.3.1.r8    | grl     |            | 21.3.1.r8-grl       
               |     | 21.2.0.r8    | grl     |            | 21.2.0.r8-grl       
               |     | 21.1.0.r8    | grl     |            | 21.1.0.r8-grl       
               |     | 20.3.6.r11   | grl     |            | 20.3.6.r11-grl      
               |     | 20.3.3.r8    | grl     |            | 20.3.3.r8-grl       
               |     | 20.3.2.r8    | grl     |            | 20.3.2.r8-grl       
               |     | 19.3.6.r11   | grl     |            | 19.3.6.r11-grl      
               |     | 19.3.6.r8    | grl     |            | 19.3.6.r8-grl       
 Java.net      |     | 20.ea.7      | open    |            | 20.ea.7-open        
               |     | 19.ea.32     | open    |            | 19.ea.32-open       
               |     | 19.ea.1.pma  | open    |            | 19.ea.1.pma-open    
               |     | 18.0.2       | open    |            | 18.0.2-open         
               |     | 18.0.1.1     | open    |            | 18.0.1.1-open       
               |     | 11.0.12      | open    |            | 11.0.12-open        
               |     | 11.0.11      | open    |            | 11.0.11-open        
               |     | 11.0.10      | open    |            | 11.0.10-open        
               |     | 11.0.2       | open    |            | 11.0.2-open         
               |     | 8.0.302      | open    |            | 8.0.302-open        
               |     | 8.0.292      | open    |            | 8.0.292-open        
               |     | 8.0.282      | open    |            | 8.0.282-open        
               |     | 8.0.265      | open    |            | 8.0.265-open        
 Liberica      |     | 18.0.2.fx    | librca  |            | 18.0.2.fx-librca    
               |     | 18.0.2       | librca  |            | 18.0.2-librca       
               |     | 18.0.1.1.fx  | librca  |            | 18.0.1.1.fx-librca  
               |     | 18.0.1.1     | librca  |            | 18.0.1.1-librca     
               |     | 17.0.4.fx    | librca  |            | 17.0.4.fx-librca    
               |     | 17.0.4       | librca  |            | 17.0.4-librca       
               |     | 17.0.3.1.fx  | librca  |            | 17.0.3.1.fx-librca  
               |     | 17.0.3.1     | librca  |            | 17.0.3.1-librca     
               |     | 11.0.16.fx   | librca  |            | 11.0.16.fx-librca   
               |     | 11.0.16      | librca  |            | 11.0.16-librca      
               |     | 11.0.15.fx   | librca  |            | 11.0.15.fx-librca   
               |     | 11.0.15.1.fx | librca  |            | 11.0.15.1.fx-librca 
               |     | 11.0.15.1    | librca  |            | 11.0.15.1-librca    
               |     | 8.0.342.fx   | librca  |            | 8.0.342.fx-librca   
               |     | 8.0.342      | librca  |            | 8.0.342-librca      
               |     | 8.0.333.fx   | librca  |            | 8.0.333.fx-librca   
               |     | 8.0.333      | librca  |            | 8.0.333-librca      
               |     | 8.0.332.fx   | librca  |            | 8.0.332.fx-librca   
 Liberica NIK  |     | 22.1.r17     | nik     |            | 22.1.r17-nik        
               |     | 22.1.r11     | nik     |            | 22.1.r11-nik        
               |     | 22.0.0.2.r17 | nik     |            | 22.0.0.2.r17-nik    
               |     | 22.0.0.2.r11 | nik     |            | 22.0.0.2.r11-nik    
               |     | 21.3.2.r17   | nik     |            | 21.3.2.r17-nik      
               |     | 21.3.2.r11   | nik     |            | 21.3.2.r11-nik      
               |     | 21.2         | nik     |            | 21.2-nik            
               |     | 21.1         | nik     |            | 21.1-nik            
               |     | 21.0.0.2.r11 | nik     |            | 21.0.0.2.r11-nik    
               |     | 21.0.0.2     | nik     |            | 21.0.0.2-nik        
 Mandrel       |     | 22.1.0.0.r17 | mandrel |            | 22.1.0.0.r17-mandrel
               |     | 22.1.0.0.r11 | mandrel |            | 22.1.0.0.r11-mandrel
               |     | 22.0.0.2.r17 | mandrel |            | 22.0.0.2.r17-mandrel
               |     | 22.0.0.2.r11 | mandrel |            | 22.0.0.2.r11-mandrel
               |     | 21.3.2.0.r17 | mandrel |            | 21.3.2.0.r17-mandrel
               |     | 21.3.2.0.r11 | mandrel |            | 21.3.2.0.r11-mandrel
               |     | 21.3.1.1.r17 | mandrel |            | 21.3.1.1.r17-mandrel
               |     | 21.3.1.1.r11 | mandrel |            | 21.3.1.1.r11-mandrel
               |     | 21.3.1.0.r17 | mandrel |            | 21.3.1.0.r17-mandrel
               |     | 21.3.1.0.r11 | mandrel |            | 21.3.1.0.r11-mandrel
               |     | 21.3.0.0     | mandrel |            | 21.3.0.0-mandrel    
               |     | 21.2.0.2     | mandrel |            | 21.2.0.2-mandrel    
               |     | 20.3.3.0     | mandrel |            | 20.3.3.0-mandrel    
 Microsoft     |     | 17.0.3       | ms      |            | 17.0.3-ms           
               |     | 11.0.15      | ms      |            | 11.0.15-ms          
 Oracle        |     | 18.0.2       | oracle  |            | 18.0.2-oracle       
               |     | 18.0.1       | oracle  |            | 18.0.1-oracle       
               |     | 17.0.4       | oracle  |            | 17.0.4-oracle       
               |     | 17.0.3       | oracle  |            | 17.0.3-oracle       
 SapMachine    |     | 18.0.2       | sapmchn |            | 18.0.2-sapmchn      
               |     | 18.0.1.1     | sapmchn |            | 18.0.1.1-sapmchn    
               |     | 17.0.4       | sapmchn |            | 17.0.4-sapmchn      
               |     | 17.0.3       | sapmchn |            | 17.0.3-sapmchn      
               |     | 17.0.3.0.1   | sapmchn |            | 17.0.3.0.1-sapmchn  
               |     | 17.0.2       | sapmchn |            | 17.0.2-sapmchn      
               |     | 11.0.16      | sapmchn |            | 11.0.16-sapmchn     
               |     | 11.0.15      | sapmchn |            | 11.0.15-sapmchn     
               |     | 11.0.15.0.1  | sapmchn |            | 11.0.15.0.1-sapmchn 
               |     | 11.0.14      | sapmchn |            | 11.0.14-sapmchn     
               |     | 11.0.14.1    | sapmchn |            | 11.0.14.1-sapmchn   
 Semeru        |     | 18.0.1.1     | sem     |            | 18.0.1.1-sem        
               |     | 17.0.3       | sem     |            | 17.0.3-sem          
               |     | 11.0.15      | sem     |            | 11.0.15-sem         
               |     | 8.0.332      | sem     |            | 8.0.332-sem         
 Temurin       |     | 18.0.2       | tem     |            | 18.0.2-tem          
               |     | 18.0.1       | tem     |            | 18.0.1-tem          
               |     | 17.0.4       | tem     |            | 17.0.4-tem          
               |     | 17.0.3       | tem     |            | 17.0.3-tem          
               |     | 11.0.16      | tem     |            | 11.0.16-tem         
               |     | 11.0.15      | tem     |            | 11.0.15-tem         
               |     | 8.0.332      | tem     |            | 8.0.332-tem         
 Trava         |     | 11.0.15      | trava   |            | 11.0.15-trava       
               |     | 11.0.9       | trava   |            | 11.0.9-trava        
               |     | 8.0.282      | trava   |            | 8.0.282-trava       
               |     | 8.0.232      | trava   |            | 8.0.232-trava       
 Zulu          |     | 18.0.2       | zulu    |            | 18.0.2-zulu         
               |     | 18.0.1       | zulu    |            | 18.0.1-zulu         
               |     | 18.0.1.fx    | zulu    |            | 18.0.1.fx-zulu      
               |     | 17.0.4       | zulu    |            | 17.0.4-zulu         
               |     | 17.0.3       | zulu    |            | 17.0.3-zulu         
               |     | 17.0.3.fx    | zulu    |            | 17.0.3.fx-zulu      
               |     | 11.0.16      | zulu    |            | 11.0.16-zulu        
               |     | 11.0.15      | zulu    |            | 11.0.15-zulu        
               |     | 11.0.15.fx   | zulu    |            | 11.0.15.fx-zulu     
               |     | 8.0.342      | zulu    |            | 8.0.342-zulu        
               |     | 8.0.332      | zulu    |            | 8.0.332-zulu        
               |     | 8.0.332.fx   | zulu    |            | 8.0.332.fx-zulu     
               |     | 7.0.352      | zulu    |            | 7.0.352-zulu        
               |     | 7.0.342      | zulu    |            | 7.0.342-zulu        
               |     | 6.0.119      | zulu    |            | 6.0.119-zulu        
================================================================================
Omit Identifier to install default version 17.0.3-tem:
    $ sdk install java
Use TAB completion to discover available versions
    $ sdk install java [TAB]
Or install a specific version by Identifier:
    $ sdk install java 17.0.3-tem
Hit Q to exit this list view
================================================================================

Thx in advance

huycozy commented 2 years ago

Hi @jfsanchez91

I don't even have that java version (8.0.222-amzn) installed in my system

Looks like you installed this version before and it's still linked. Could you try removing this directory /home/USER/.sdkman/candidates/java/8.0.222-amzn/ and retry?

jfsanchez91 commented 2 years ago

@huycozy that folder does not exist.

huycozy commented 2 years ago

@jfsanchez91 Could you try creating a symbolic link from /home/USER/.sdkman/candidates/java/8.332.08.1-amzn/bin/java to /home/USER/.sdkman/candidates/java/8.0.222-amzn/bin/java then retry flutter doctor -v?

jfsanchez91 commented 2 years ago

@huycozy I already did that as a workaround, but I would really like to get rid of it. Why is flutter looking for that path?

huycozy commented 2 years ago

@jfsanchez91 It looks like a Flutter tool's issue. Keeping this open for further investigation from the team.

gnprice commented 1 year ago

I happened to be looking at this code just now, so I tried to work out how these reported symptoms could happen.

As far as I can tell, the answer will have to involve either the JAVA_HOME environment variable, or the PATH environment variable, pointing to that Java installation. The code that drives that "Java binary at:" message in the flutter doctor -v output is the findJavaBinary method in packages/flutter_tools/lib/src/android/android_sdk.dart (via its call site in AndroidValidator.validate), and I don't see another way it could be getting the answer it gets.

That leaves the mystery of why the flutter tool is seeing such a JAVA_HOME (or such a PATH), when echo $JAVA_HOME shows a different value in the user's shell.

I don't have an answer for that mystery. But, knowing nothing about how snaps work, my wild guess is that it's something to do with the snap. Perhaps /home/USER/.sdkman/candidates/java/8.0.222-amzn was the value of JAVA_HOME when the snap was installed, and perhaps that somehow got baked into the snap? (Again, I have no idea how snaps work.)

@jfsanchez91 If you can still reproduce this issue, and you're interested in debugging it, my suggestion would be to use strace, with a command like this:

strace -f -eexecve -v -s1024 flutter doctor -v 2>/tmp/trace

That'll dump a few hundred lines to the /tmp/trace file. Then inspect that to see if the value of JAVA_HOME ever changes:

$ grep -o '"JAVA_HOME=[^"]*"' /tmp/trace | uniq -c

and to see if the value of PATH ever changes:

$ grep -o '"PATH=[^"]*"' /tmp/trace | uniq -c