How do I tell Gradle to use specific JDK version?
Two ways
- In
gradle.properties
in the.gradle
directory in yourHOME_DIRECTORY
setorg.gradle.java.home=/path_to_jdk_directory
or:
In your
build.gradle
compileJava.options.fork = true
compileJava.options.forkOptions.executable = '/path_to_javac'
gradlew uses wrong Java version
A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects.
https://developer.android.com/studio/intro/studio-config.html#jdk
This however, is only for building your apps within Android Studio, not from the terminal with gradlew
, otherwise, it'll use whatever is on your OS's $PATH
variable.
In order to use the embedded JDK, you at least need to set JAVA_HOME
, for example on Linux/Mac,
$ export JAVA_HOME=/path/to/AndroidStudio/jdk # TODO: Find this
$ ./gradlew
My recommendation, however, is to use the mechanism for your OS for installing Java.
For easy Java library management (on Linux & Mac), you can try using sdkman
How to enforce a java compiler version with gradle?
I use the following:
task checkJavaVersion << {
if (!JavaVersion.current().isJava6()) {
String message = "ERROR: Java 1.6 required but " +
JavaVersion.current() +
" found. Change your JAVA_HOME environment variable.";
throw new IllegalStateException(message);
}
}
compileJava.dependsOn checkJavaVersion
Azure build error: Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8
My error is solved by adding below lines into azure-pipelines.yml
file:
steps:
- task: JavaToolInstaller@0
inputs:
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
Related Topics
How to Autowire a Component Which Is Having Constructor With Arguments in Springboot Application
How to Save a File Downloaded With Httpclient into a Specific Folder
Post and Get for the Same Url - Controller - Spring
Kafka: Failed to Update Metadata After 60000 Ms
Avoid Keycloak Default Login Page and Use Project Login Page
How to Pass Authentication Credentials in Vba
How to Get Response as Json With Responseentity in Java
How to Split a Huge Zip File into Multiple Volumes
Badpaddingexception Decrypting the Encrypted Data in Android
Getting Versioncode and Versionname from Google Play
How to Append a Query Parameter to an Existing Url
Subscript and Superscript a String in Android
How to Send Text to Textarea in Div Element Using Selenium
Placing a Jlabel At a Specific X,Y Coordinate on a Jpanel
How to Update a Jsf Component from a Jsf Backing Bean Method