Skip to content

Android Gradle Plugin Requires Java 11

Problem

When building Android projects with newer versions of Android Studio and the Android Gradle plugin, you may encounter the following error:

> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.

This error occurs because newer versions of the Android Gradle plugin (version 7.0.0 and above) require Java 11 or later, while your development environment is configured to use Java 1.8 (Java 8).

Solutions

The simplest solution for most users is to update the Gradle JDK setting directly in Android Studio:

  1. Open Preferences (macOS) or Settings (Windows/Linux)
  2. Navigate to Build, Execution, DeploymentBuild ToolsGradle
  3. Under Gradle JDK, select a Java 11 or later JDK
  4. Click OK and rebuild your project

Gradle JDK Settings

Method 2: Set Java Home in gradle.properties

If the IDE setting doesn't work or you need to configure this for command-line builds:

  1. Open your project's gradle.properties file
  2. Add the following line with the correct path to your JDK 11 installation:
properties
# macOS
org.gradle.java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home

# Windows
org.gradle.java.home=C:\Program Files\Java\jdk-11.0.15

# Linux
org.gradle.java.home=/usr/lib/jvm/java-11-openjdk-amd64

Method 3: Update Environment Variables

For command-line builds and terminal usage:

macOS/Linux

Add to your shell profile (~/.bash_profile, ~/.zshrc, etc.):

bash
export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"

Reload your shell configuration:

bash
source ~/.zshrc  # or ~/.bash_profile

Windows

  1. Open System Properties → Environment Variables
  2. Create or update the JAVA_HOME variable to point to your JDK 11 installation
  3. Add %JAVA_HOME%\bin to your PATH variable
  4. Restart your terminal/IDE

Method 4: Check Global Gradle Configuration

Sometimes a global Gradle configuration overrides your project settings. Check for a global gradle.properties file at:

  • macOS/Linux: ~/.gradle/gradle.properties
  • Windows: C:\Users\<username>\.gradle\gradle.properties

Remove or update any org.gradle.java.home entries that might be forcing Java 8.

Platform-Specific Solutions

For Flutter Projects

Add the Java home path to your android/gradle.properties file:

properties
org.gradle.java.home=/path/to/jdk-11

For CI/CD Pipelines

GitHub Actions

Update your workflow to use JDK 11:

yaml
- name: Set up JDK 11
  uses: actions/setup-java@v3
  with:
    distribution: 'zulu'
    java-version: 11

Azure DevOps

Add this task to your pipeline:

yaml
- task: JavaToolInstaller@0
  inputs:
    versionSpec: '11'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

MS App Center

Set the environment variable in build configuration:

  • JAVA_HOME = $(JAVA_HOME_11_X64)

Verification

After applying any solution, verify that Gradle is using the correct Java version:

bash
cd android  # For React Native/Flutter projects
./gradlew --version

Look for the JVM version in the output:

JVM:          11.0.12 (JetBrains s.r.o. 11.0.12+0-b1504.28-7817840)

Alternative: Downgrade Android Gradle Plugin

If you cannot upgrade to Java 11, you can downgrade the Android Gradle plugin (not recommended for new projects):

gradle
// In your project-level build.gradle
plugins {
    id 'com.android.application' version '4.2.0' apply false
    id 'com.android.library' version '4.2.0' apply false
}

WARNING

Downgrading the Android Gradle plugin may limit your access to newer Android features and optimizations.

Troubleshooting

  • Paths with spaces: On Windows, use the short path format (Progra~1 instead of Program Files) or escape spaces properly
  • Multiple JDK installations: Use java -XshowSettings:properties -version to identify all installed JDKs
  • Android Studio bundled JDK: Recent versions include a compatible JDK at Android Studio.app/Contents/jbr/Contents/Home (macOS)

Conclusion

The "Android Gradle plugin requires Java 11" error is resolved by ensuring your build environment uses Java 11 or later. The recommended approach is to configure the Gradle JDK in Android Studio settings or set the org.gradle.java.home property in your gradle.properties file. For CI/CD environments, ensure your build agents are configured with the correct Java version.