79771951

Date: 2025-09-22 18:44:06
Score: 1.5
Natty:
Report link

In Android Studio Ladybug 2024.2.1 or IntelliJ IDEA, this error can happen even if you have Java 21 installed and enabled by default. For example, you could set your $JAVA_HOME environment variable to use the JDK that comes from Android Studio, using this guide Using JDK that is bundled inside Android Studio as JAVA_HOME on Mac :

# For ~/.bash_profile or ~/.zshrc
export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"

But for some reason, an Android project that declares that it needs Java 17 in a build.gradle file cannot be compiled with Java 21.

java {
  sourceCompatibility JavaVersion.VERSION_17
  targetCompatibility JavaVersion.VERSION_17
}

kotlin {
  jvmToolchain(17)
}

You'll see an error like this when you try to build the app:

org.gradle.jvm.toolchain.internal.NoToolchainAvailableException:
No matching toolchains found for requested specification:
{languageVersion=17, vendor=any, implementation=vendor-specific} for MAC_OS on aarch64.

Could not determine the dependencies of task ':app:compileKotlin'.
> No locally installed toolchains match and toolchain download repositories have not been configured.

The solution is to download a specific Java 17 JDK/SDK manually, and make your project use it:

Android Studio - Settings Dialog for Gradle Projects

Android Studio - Settings - Gradle - Download JDK

Reasons:
  • Blacklisted phrase (1): this guide
  • Blacklisted phrase (1): How do I
  • Whitelisted phrase (-1): solution is
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: Mr-IDE