Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. Error
Asked Answered
B

5

9

I want to publish a library with Jitpackio. When I publish the library I get 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`."

Gradle Version : 7.0.2

My Gradle JDK Version

Can you help me?

Byplay answered 1/8, 2021 at 10:53 Comment(1)
Have you checked all the three options if it points to an old JDK version? What else have you tried so far, the options are quite easily to understand especially if you search the internet for them.Hoot
B
33

The problem was that JitPack.io was running with JDK1.8 on its own. Add a jitpack.yml file to the project file with this content:

jdk:
  - openjdk11

When I did that the problem went away.

Byplay answered 12/8, 2021 at 11:51 Comment(2)
Thanks! This answer made my day!Caseinogen
This should've been mentioned in the official JitPack docs. This worked like a charm.Chanukah
C
4

According to AGP release note here

When using Android Gradle plugin 7.0 to build your app, JDK 11 is now required to run Gradle. Android Studio Arctic Fox bundles JDK 11 and configures Gradle to use it by default, which means that most Android Studio users do not need to make any configuration changes to their projects.

JDK 11 is required if you using AGP 7.0.

You can modify AS JDK version like below (Only effect run app build project in AS small hammer or run action)enter image description here if Android Studio Arctic Fox | 2020.3.1 you use .

For some one building android app with AGP 7.0 with command line

  1. Modify JAVA_HOME value path to JDK 11 (Which will effect all of project on environment)
  2. Declare "org.gradle.java.home = path to JDK 11" in special project gradle.properties file (Effect to only this project)
Christychristye answered 2/8, 2021 at 12:32 Comment(2)
I am using "Android Studio Arctic Fox | 2020.3.1" . Gradle JDK version 11.0.10 but didnt work this solution :(Byplay
@gokmenBayram Which options you did for fixing building error ? Why you import Application plugin while building android library (AAR) ?Christychristye
S
1

Create jitpack.yml in root project dir.

jdk:
  - openjdk11
before_install:
  - sdk install java 11.0.10-open
  - sdk use java 11.0.10-open

It's working for me. enter image description here

Stanstance answered 27/12, 2021 at 2:4 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Magdalenamagdalene
A
0

solution in reviewed in jitpack github page: here

as said : you should create a file in root of project named jitpack.yml contain

jdk:
  -openjdk11 

then change build.gradle file in library as :

apply plugin: 'com.android.library' 
apply plugin:'maven-publish'
.
.
afterEvaluate {
publishing {
    publications {
        release(MavenPublication) {
            from components.release
            groupId = "ntk.android.base"
            artifactId = 'baseActivity'
            version = version
        }
    }
}

}

Andrien answered 22/9, 2021 at 18:2 Comment(0)
F
0

Only add jitpack.yml isn't working for me in gradle 7.0.2, but change gradle jdk works, according to this blog

Faille answered 9/3, 2022 at 14:14 Comment(1)
Please add your answer as a comment or explain more by yourself.Isogloss

© 2022 - 2024 — McMap. All rights reserved.