개발/안드로이드

안드로이드 스튜디오 오류 "Android Gradle 플러그인은 실행하기 위해 Java 11이 필요합니다. 현재 Java 1.8을 사용하고 있습니다."

맨날치킨 2023. 3. 5. 16:06
반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

Android Studio Error "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8"

안드로이드 스튜디오 오류 "Android Gradle 플러그인은 실행하기 위해 Java 11이 필요합니다. 현재 Java 1.8을 사용하고 있습니다."

 문제 내용 

I downloaded the newest Android Studio, and I wanted to run the Android Jetpack Compose Project, but when I ran it, I got the error:

저는 최신 버전의 Android Studio를 다운로드하고 Android Jetpack Compose 프로젝트를 실행하려 했으나 실행 중 다음과 같은 오류가 발생했습니다:
> 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`.

 

I already downloaded Java 11 and added Java 11 in gradle.properties.

저는 이미 Java 11을 다운로드하고 gradle.properties에 Java 11을 추가했습니다.
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home

 

The JAVA_HOME shows Java 11, but when I run, it doesn't work - /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home

JAVA\_HOME은 Java 11을 나타내지만 실행할 때 작동하지 않습니다 - /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home

 

How should I do?

어떻게 해야 하나요?

 

My Android Studio version

My Android Studio version는 Android Studio의 버전을 나타내는 문장입니다.

Enter image description here

My Java version

제 자바 버전
java 11.0.10 2021-01-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.10+8-LTS-162, mixed mode)

 

My gradle-wrapper.properties

제 gradle-wrapper.properties 파일입니다.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip

 

build.gradle classpath

build.gradle의 classpath입니다.
classpath "com.android.tools.build:gradle:7.0.0-alpha13"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"

 

File build.gradle

build.gradle 파일
plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 30

    defaultConfig {
        applicationId "com.example.testandroid3"
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = "11"
        useIR = true
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion '1.4.31'
    }
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha02'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
}

 

 

 높은 점수를 받은 Solution 

Make sure that your Gradle is using the proper JDK. Try running ./gradlew --version in your project's directory. The output should be something like this:

Gradle이 올바른 JDK를 사용하고 있는지 확인하세요. 프로젝트 디렉토리에서 ./gradlew --version을 실행해보세요. 출력 결과는 다음과 같아야 합니다:
Gradle 7.0-rc-2
------------------------------------------------------------

Build time:   2021-04-01 21:26:39 UTC
Revision:     912a3368b654b71250dfc925a20d620393

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.10 (Ubuntu 11.0.10+9-Ubuntu-0ubuntu1.20.10)
OS:           Linux 5.11.4-051104-generic amd64

 

If the JVM points to version 1.8 then you should change it in settings. You can find it in PreferencesBuild, Execution, DeploymentBuild ToolsGradle → *Gradle JDK.

만약 JVM이 1.8 버전을 가리킨다면, 설정에서 변경해야 합니다. 설정은 Preferences → Build, Execution, Deployment → Build Tools → Gradle → \*Gradle JDK에서 찾을 수 있습니다.

Enter image description here

 

 

 가장 최근 달린 Solution 

When I upgraded to Android Studio 15 (Dolphin) I got this error, and it is sooooo easy to fix. This answer is the easiest, fastest and the best...

안드로이드 스튜디오 15(Dolphin)로 업그레이드하면서 이 오류가 발생했는데, 이것을 고치는 것은 매우 쉽습니다. 이 답변이 가장 쉽고 빠르며 최선입니다...

 

In Android Studio I just did this:

안드로이드 스튜디오에서는 다음과 같이 수행했습니다:

 

PreferencesBuild,Execution,DeploymentBuild Tools → *Gradle. Select Java 11 or 12, etc..

환경설정 → 빌드, 실행, 배포 → 빌드 도구 → Gradle. Java 11이나 12 등을 선택하세요.

 

Easy peasy

매우 쉽습니다.

 

See the picture.

사진을 보세요.

Enter image description here

 

 

출처 : https://stackoverflow.com/questions/66980512/android-studio-error-android-gradle-plugin-requires-java-11-to-run-you-are-cur

반응형