I would like to set in a Gradle build file the required Java version e.g. 7 or 8 without having to specify the actual path to a local JDK installation.
Is this possible ?
Set the JDK version Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac). Under Gradle JDK, choose the Embedded JDK option.
Gradle can only run on Java version 8 or higher. Gradle still supports compiling, testing, generating Javadoc and executing applications for Java 6 and Java 7. Java 5 and below are not supported.
You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line.
Access the Gradle JVM settingsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Build, Execution, Deployment | Build Tools | Gradle. On the Gradle settings page, under the Gradle section, use the Gradle JVM option to check the Gradle version used for importing a project.
TLDR; Thanks @franklin-yu "targetCompatibility = '1.7' -> your user can compile with 8 and run with 7."
See Gradle, "sourceCompatibility" vs "targetCompatibility"?
targetCompatibility = '1.7'
does the trick for e.g. Java 7
Use sourceCompatibility = '1.7'
for the language level
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With