Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Android Studio default gradle JDK to 11

Getting this message when I click run:

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

The answers from Error message "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8" to change the Gradle JDK in settings work. but only for that one project. When I create a new project, Android Studio automatically uses default 1.8 again.

I have 11 available, AS just doesn't automatically use it. Things I tried: changed the JAVA_HOME env to the location for JDK 11 here, but still get the same error.

Invalid cache /restart a bunch of time does nothing

How to set it once and apply it to all future new projects?

enter image description here

Attaching app/build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.grid"
        minSdk 22
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}

top level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 223
BabyishTank Avatar asked Dec 04 '25 14:12

BabyishTank


1 Answers

Multiple Android Studio Installed?

Short Answer:

Just delete the other version and it should fix the problem.

Long answer:

I had two versions of Android Studio installed Android 4.2 and Android Arctic Fox. Both Android Studio had different Gradle JDK version installed.

This is what I was seeing in Arctic Fox Gradle Settings. (Default selection was 1.8)

enter image description here

My theory:

If you notice Gradle JDK is installed under Applications/Android Studio/Content/

It's my assumption that Gradle Settings page pulls up all the installed Gradle JDK versions. And there is no option to set the default version in Settings page. So the first Gradle version becomes the default.

I don't know if it is alphabetically sorted or based on Download timestamp.

But I believe it is based on the timestamp. The oldest installed version gets to the top in the list.

Here is a supporting observation. When I deleted Android Studio 4.2 and ctrl+z (Undo) it the list order changed.

enter image description here

Disclaimer:

I could be completely wrong as I don't have any official doc, link that support this claim. It is just a theory.
And I also understand that it is not an ideal solution. As deleting old Android Studio may not be the option for everyone.

like image 97
Rohit Singh Avatar answered Dec 07 '25 04:12

Rohit Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!