Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Flutter "Toolchain installation `usr/lib/jvm/java-21-openjdk` does not provide the required capabilities" error

I keep getting this warning on (Fedora) Linux when opening a Flutter project of mine inside VS Code. I changed JAVA_HOME and used flutter config --jdk-dir="/usr/lib/jvm/java-24-openjdk/ to change my Java version but it still keeps coming up with a warning referencing OpenJDK 21 (so before we even get to the question of the right java version, why is it stuck on version 21?):

The supplied phased action failed with an exception.
Could not create task ':app:compileDebugAndroidTestJavaWithJavac'.
Failed to calculate the value of task ':app:compileDebugAndroidTestJavaWithJavac' property 'javaCompiler'.
Toolchain installation '/usr/lib/jvm/java-21-openjdk' does not provide the required capabilities: [JAVA_COMPILER]

I even added org.gradle.java.home=/usr/lib/jvm/java-24-openjdk to android/gradle.properties.

This is the output of flutter doctor --verbose:

[✓] Flutter (Channel stable, 3.32.6, on Fedora Linux 41 (KDE Plasma) 6.15.5-100.fc41.x86_64, locale en_GB.UTF-8) [120ms]
    • Flutter version 3.32.6 on channel stable at /home/bitmapp3r/dev/flutter-sdk
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 077b4a4ce1 (6 days ago), 2025-07-08 13:31:08 -0700
    • Engine revision 72f2b18bb0
    • Dart version 3.8.1
    • DevTools version 2.45.1

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,977ms]
    • Android SDK at /home/bitmapp3r/Android/Sdk
    • Platform android-36, build-tools 36.0.0
    • Java binary at: /usr/lib/jvm/java-17-openjdk/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (Red_Hat-17.0.15.0.6-1) (build 17.0.15+6)
    • All Android licenses accepted.

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

[✓] Linux toolchain - develop for Linux desktop [556ms]
    • clang version 19.1.7 (Fedora 19.1.7-4.fc41)
    • cmake version 3.30.8
    • ninja version 1.12.1
    • pkg-config version 2.3.0
    • OpenGL core renderer: AMD Radeon Graphics (radeonsi, renoir, ACO, DRM 3.63, 6.15.5-100.fc41.x86_64)
    • OpenGL core version: 4.6 (Core Profile) Mesa 25.0.7
    • OpenGL core shading language version: 4.60
    • OpenGL ES renderer: AMD Radeon Graphics (radeonsi, renoir, ACO, DRM 3.63, 6.15.5-100.fc41.x86_64)
    • OpenGL ES version: OpenGL ES 3.2 Mesa 25.0.7
    • OpenGL ES shading language version: OpenGL ES GLSL ES 3.20
    • GL_EXT_framebuffer_blit: yes
    • GL_EXT_texture_format_BGRA8888: yes

[✓] Android Studio (version 2025.1.1) [21ms]
    • Android Studio at /opt/android-studio
    • 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
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)

[✓] VS Code (version unknown) [19ms]
    • VS Code at /usr/share/code
    • Flutter extension version 3.114.0
    ✗ Unable to determine VS Code version.

[✓] Connected device (3 available) [261ms]
    • SM S911B (mobile) • RFCX808ZYCE • android-arm64  • Android 15 (API 35)
    • Linux (desktop)   • linux       • linux-x64      • Fedora Linux 41 (KDE Plasma) 6.15.5-100.fc41.x86_64
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 138.0.7204.100

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

• No issues found!

Here is my android/app/build.gradle.kts (I omitted the project name)

plugins {
    id("com.android.application")
    id("kotlin-android")
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id("dev.flutter.flutter-gradle-plugin")
}

android {
    namespace = "com.example.x"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.x"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.getByName("debug")
        }
    }
}

flutter {
    source = "../.."
}
like image 741
Bitmapper Avatar asked Mar 14 '26 06:03

Bitmapper


1 Answers

i have the same issue and solve it buy install the java with devel since fedora in default install java headless (does not contains javac)

run this command in the terminal

sudo dnf install java-devel

if this not works use the java that comes with the android studio

in android/gradle.properties add the java

org.gradle.java.home=/{android_studio_location}/android-studio/jbr/
like image 194
Hesham Alnahas Avatar answered Mar 16 '26 21:03

Hesham Alnahas