0

I have cloned the flutter repo and installed the Android SDK command-line tools, setting them up in $HOME/Android. I then made flutter aware of the SDK installation by setting $ANDROID_HOME to $HOME/Android. Things seem to have worked out, with <path-to-flutter> doctor finding

  • Android SDK
  • my Java JDK 8 installation (openjdk-8-jdk package on Ubuntu 18.04), and
  • a connected Android phone with USB debugging

I am now trying to follow the test-run instructions for building a first app on the command line. <path-to-flutter> create myapp works and produces a myapp directory. I then try to run the resulting starter app:

cd myapp
~/myapp$ ANDROID_HOME=~/Android JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 <path-to-flutter> run

This results in the following error:

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'.                    
> 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

I have seen this issue discussed before, 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 $JAVA_HOME, and besides, running

./android/gradlew build

inside the myapp directory does work:

~/myapp$ ./android/gradlew build

> 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

So this seems to be specific to flutter itself somehow, rather than gradle.

grobber
  • 1,083
  • 1
  • 9
  • 20

2 Answers2

3

It turns out this must have been a path issue. The Flutter starter app builds (and pops up on my device) after inserting the following snippet in a file sourced in my profile (my .bashrc):

# Java
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64

# Android
export ANDROID_HOME=${HOME}/Android
export ANDROID_SDK_ROOT=${HOME}/Android

# Flutter
export FLUTTER_HOME=${HOME}/repos/flutter
PATH=${FLUTTER_HOME}/bin:$PATH; export PATH
grobber
  • 1,083
  • 1
  • 9
  • 20
1

you can do like this -->

sudo apt-get remove --auto-remove openjdk*
sudo apt-get install openjdk-8-jre

now goto to home and visible your hidden folder by pressing ctrl+h

Now open .bashrc or your .rc

paste these on last

export PATH="$PATH:/snap/bin/flutter/bin"
export PATH="$PATH:/usr/bin/java"
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
export ANDROID_SDK_ROOT=/home/<YOUR USER NAME>/Android/Sdk

then run

source ~/bashrc
flutter doctor -v
Rasel Khan
  • 2,976
  • 19
  • 25