Skip to content

Resolving "No matching variant of com.android.tools.build:gradle:7.4.0 was found"

This error occurs when your Android project requires Java 11+ but your environment uses Java 8. The Android Gradle Plugin (AGP) 7.4.0 and later need Java 11 runtime compatibility. Below are solutions to resolve this.


Step 1: Configure Gradle JDK in Android Studio

Change the JDK version Gradle uses in Android Studio:

  1. Go to File → Settings → Build, Execution, Deployment → Build Tools → Gradle
    (On Mac: Android Studio → Preferences → Build, Execution, Deployment → Build Tools → Gradle)
  2. Under Gradle JDK, select:
    • JDK 11 for AGP 7.4.0
    • JDK 17 for AGP 8.0.0+ (e.g., 11 or 17 Amazon Corretto, Temurin, or official Oracle JDK)
      Gradle JDK Settings

Step 2: Set JDK in gradle.properties

Add this to your project's gradle.properties file:

properties
# For JDK 11
org.gradle.java.home=/path/to/your/jdk-11

# For JDK 17 (required for AGP 8.0.0+ and Kotlin Multiplatform)
org.gradle.java.home=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home

Note: Update the path to match your local JDK installation.


Step 3: Verify Module-Level Settings

In your app module's build.gradle.kts, confirm Java/Kotlin compatibility matches the JDK:

kotlin
android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11 // or VERSION_17
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = "11" // or "17"
    }
}

Step 4: CI/CD Setup

For CI pipelines (e.g., GitHub Actions), configure the Java version:

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

Step 5: Additional Fixes

Check Environment Variables

Verify JAVA_HOME points to JDK 11/17:

bash
echo $JAVA_HOME  # Should show JDK 11+ path

Update it in your OS if incorrect.

Invalidate Caches

If the issue persists:

  1. File → Invalidate Caches → "Invalidate and Restart"
  2. If using AGP 8.0.0+, ensure plugins are up to date:
    gradle
    // Project-level build.gradle
    plugins {
        id 'com.android.application' version '8.0.0' apply false
        id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
    }

Kotlin Multiplatform (KMM) Projects

Use JDK 17 to avoid iOS build issues.


Why This Fix Works

  • AGP 7.4.0+ targets Java 11 bytecode, while Java 8 lacks required features.
  • The error explicitly states:
    declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
  • Aligning your environment’s JDK with AGP’s requirements resolves this mismatch.