title: JDK installation not found by flutter starter app
body: <p>I have cloned <a href="https://github.com/flutter/flutter" rel="nofollow noreferrer">the flutter repo</a> and installed the <a href="https://developer.android.com/studio" rel="nofollow noreferrer">Android SDK command-line tools</a>, setting them up in <code>$HOME/Android</code>. I then made <code>flutter</code> aware of the <code>SDK</code> installation by setting <code>$ANDROID_HOME</code> to <code>$HOME/Android</code>. Things seem to have worked out, with <code>&lt;path-to-flutter&gt; doctor</code> finding</p>
  <ul>
  <li><code>Android SDK</code></li>
  <li>my Java JDK 8 installation (<code>openjdk-8-jdk</code> package on <code>Ubuntu 18.04</code>), and</li>
  <li>a connected Android phone with USB debugging</li>
  </ul>
  <p>I am now trying to follow the <a href="https://flutter.dev/docs/get-started/test-drive?tab=terminal" rel="nofollow noreferrer">test-run instructions</a> for building a first app on the command line. <code>&lt;path-to-flutter&gt; create myapp</code> works and produces a <code>myapp</code> directory. I then try to run the resulting starter app:</p>
  <pre><code>cd myapp
  ~/myapp$ ANDROID_HOME=~/Android JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 &lt;path-to-flutter&gt; run
  </code></pre>
  <p>This results in the following error:</p>
  <pre><code>Launching lib/main.dart on ONEPLUS A6013 in debug mode...
                                                                          
  FAILURE: Build failed with an exception.                                
                                                                          
  * What went wrong:                                                      
  Execution failed for task ':app:compileDebugKotlin'.                    
  &gt; Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
                                                                          
  * Try:                                                                  
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                          
  * Get more help at https://help.gradle.org                              
                                                                          
  BUILD FAILED in 10s                                                     
  Running Gradle task 'assembleDebug'...                                  
  Running Gradle task 'assembleDebug'... Done                        11.0s
  Exception: Gradle task assembleDebug failed with exit code 1
  </code></pre>
  <p>I have seen this issue <a href="https://stackoverflow.com/questions/32289233/gradle-cannot-find-jdk">discussed</a> <a href="https://stackoverflow.com/questions/55286542/kotlin-could-not-find-the-required-jdk-tools-in-the-java-installation">before</a>, but none of those replies seem to address it (in my case, at least). You can see from the command that I am exporting the right <code>$JAVA_HOME</code>, and besides, running</p>
  <pre><code>./android/gradlew build
  </code></pre>
  <p>inside the <code>myapp</code> directory does work:</p>
  <pre><code>~/myapp$ ./android/gradlew build
  
  &gt; Task :buildEnvironment
  
  ------------------------------------------------------------
  Root project
  ------------------------------------------------------------
  
  classpath
  No dependencies
  
  A web-based, searchable dependency report is available by adding the --scan option.
  
  BUILD SUCCESSFUL in 319ms
  1 actionable task: 1 executed
  </code></pre>
  <p>So this seems to be specific to <code>flutter</code> itself somehow, rather than <code>gradle</code>.</p>