javaandroidgradlejitpack

"Android Gradle plugin requires Java 11 to run" While publishing jitpack library


I'm trying to publish an empty jitpack library for test purposes by using this github repo

But I'm having

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> 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`.

Full error : https://jitpack.io/com/github/emreakcan/android-lib-jitpack-test/2.0.0/build.log

My IDE settings are set to version 11, Java 1.8 is not even installed on my mac.

emre@Emres-MacBook-Pro / % java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment OpenLogic-OpenJDK (build 11.0.8+10-adhoc.admin.jdk11u)
OpenJDK 64-Bit Server VM OpenLogic-OpenJDK (build 11.0.8+10-adhoc.admin.jdk11u, mixed mode)
emre@Emres-MacBook-Pro / % 

If I add

org.gradle.java.home=/Library/Java/JavaVirtualMachines/openlogic-openjdk-11.jdk/Contents/Home

I'm having the following error

* What went wrong:
Value '/Library/Java/JavaVirtualMachines/openlogic-openjdk-11.jdk/Contents/Home' given for org.gradle.java.home Gradle property is invalid (Java home supplied is invalid)

My gradle is also set to 11

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
    jvmTarget = '11'
}

I tried those links Error: Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. -& Failed to apply plugin 'com.android.internal.application'

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

Project works on my local, I'm having those errors on jitpack website once when I push my tags


Solution

  • Solved by using a jitpack.yml (added it into project root), turns out jitpack using 1.8 as default and doesn't care about what you set on gradle.

    # configuration file for building snapshots and releases with jitpack.io
    jdk:
      - openjdk11
    before_install:
      - ./scripts/prepareJitpackEnvironment.sh
    

    Details https://jitpack.io/docs/BUILDING/#java-version