I ran the following comment:
./gradlew app:installDebug
only to be met with the log:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.2'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
My version of gradle is 5.1.1:
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------
Build time: 2019-01-10 23:05:02 UTC
Revision: 3c9abb645fb83932c44e8610642393ad62116807
Kotlin DSL: 1.1.1
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9-LTS)
OS: Mac OS X 10.13.6 x86_64
I'm not sure how to proceed (I tried upgrading/downgrading, but nothing has worked so far).
UPDATE: When I ran ./gradlew --version
, I got the following:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.2'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
My gradle-wrapper.properties
contains:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
There are two different Gradle applications in your system.
the system-wide Gradle
This application is invoked bygradle (arguments)
.the gradle-wrapper
The gradle-wrapper is specific to every project and can only be invoked inside the project's directory, using the command./gradlew (arguments)
.
Your system-wide gradle version is 5.1.1 (as the OP explained in the comments, running the command gradle --version
returned version 5.1.1).
However, the failure is the result of a call to the gradle-wrapper (./gradlew
). Could you check your project's gradle wrapper version? To do that, execute ./gradlew --version
inside your project's folder, in the directory where the gradlew and gradlew.bat files are.
Update 1:
As running ./gradlew --version
failed, you can manually check your wrapper's version by opening the file:
(project's root folder)/gradle/wrapper/gradle-wrapper.properties
with a simple text editor. The "distributionUrl" inside should tell us what the wrapper's version is.
Update 2:
As per the OP's updated question, the gradle-wrapper's version is 4.1RC1.
Gradle added support for JDK 11 in Gradle 5.0. Hence since 4.1RC does not support JDK 11 this is definitely a problem.
The obvious way, would be to update your project's gradle-wrapper to version 5.0. However, before updating, try running gradle app:installDebug
. This will use your system-wide installed Gradle whose version is 5.1.1 and supports Java 11. See if this works. If it does, then your buildscript (file build.gradle) is not affected by any breaking changes between v.4.1RC1 and v.5.1.1 and you can then update your wrapper by executing from the command line inside your project's folder: gradle wrapper --gradle-version=5.1.1
[*].
If gradle app:installDebug
fails to execute correctly, then maybe you need to upgrade your Gradle buildscript. For updating from v.4.1RC1 to 5.1.1, the Gradle project provides a guide (1, 2) with breaking changes and deprecated features between minor releases, so that you can update gradually to the latest version.
Alternatively, if for some reason you can't or don't want to upgrade your Gradle buildscript, you can always choose to downgrade your Java version to one that Gradle 4.1RC1 supports.
[*] As correctly pointed out in another answer by @lupchiazoem, use gradle wrapper --gradle-version=5.1.1
(and not ./gradlew
as I had originally posted there by mistake). The reason is Gradle runs on Java. You can update your gradle-wrapper using any working Gradle distribution, either your system-wide installed Gradle or the gradle-wrapper itself. However, in this case your wrapper is not compatible with your installed Java version, so you do have to use the system-wide Gradle (aka gradle
and not ./gradlew
).
As distributionUrl
is still pointing to older version, upgrade wrapper using:
gradle wrapper --gradle-version 5.1.1
Note: Use gradle
and not gradlew
In my case the JAVA_HOME
variable was set to /usr/lib/jvm/jdk-11.0.2/
. It was sufficient to unset the variable like this:
$ export JAVA_HOME=
Because wrapper version does not support 11+ you can make simple trick to cheat newer version of InteliJ forever.
press3x Shift -> type "Switch Boot JDK" -> and change for java 8.
https://blog.jetbrains.com/idea/2015/05/intellij-idea-14-1-4-eap-141-1192-is-available/
Or If you want to work with java 11+ you simply have to update wrapper version to 4.8+
I've had the same issue. Upgrading to gradle 5.0 did the trick for me.
This link provides detailed steps on how install gradle 5.0: https://linuxize.com/post/how-to-install-gradle-on-ubuntu-18-04/
I ran into a similar issue. I deleted these:
- libraries and caches from the .idea folder ( YourApp > .idea > .. ) AND
contents of the build folder.
then rebuild.
* DON'T FORGET TO BACKUP YOUR PROJECT FIRST *
I ran into the same issue in Ubuntu 18.04.3 LTS. In my case, apt installed gradle version 4.4.1. The already-install java version was 11.0.4
The build message I got was
Could not determine java version from '11.0.4'.
At the time, most of the online docs referenced gradle version 5.6, so I did the following:
sudo add-apt-repository ppa:cwchien/gradle
sudo apt update
sudo apt upgrade gradle
Then I repeated the project initialiation (using "gradle init" with the defaults). After that, "./gradlew build" worked correctly.
I later read a comment regarding a change in format of the output from "java --version" that caused gradle to break, which was fixed in a later version of gradle.
To put long answer short, upgrade your gradlew
using the system gradle
tool. Note that the below upgrade works even if your system gradle
version is < 5
.
gradle wrapper --gradle-version=5.1.1
In my case, I was trying to build and get APK for an old Unity 3D project (so that I can play the game in my Android phone). I was using the most recent Android Studio version, and all the SDK packages I could download via SDK Manager in Android Studio. SDK Packages was located in
C:/Users/Onat/AppData/Local/Android/Sdk
And the error message I got was the same except the JDK (Java Development Kit) version "jdk-12.0.2" . JDK was located in
C:\Program Files\Java\jdk-12.0.2
And Environment Variable in Windows was JAVA_HOME : C:\Program Files\Java\jdk-12.0.2
After 3 hours of research, I found out that Unity does not support JDK 10. As told in https://forum.unity.com/threads/gradle-build-failed-error-could-not-determine-java-version-from-10-0-1.532169/
. My suggestion is:
- Uninstall unwanted JDK if you have one installed already. https://www.java.com/tr/download/help/uninstall_java.xml
- Head to
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- Login to/Open a Oracle account if not already logged in.
- Download the older but functional JDK 8 for your computer set-up(32 bit/64 bit, Windows/Linux etc.)
- Install the JDK. Remember the installation path. (https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/)
- If you are using Windows, Open Environment Variables and change Java Path via Right click My
Computer/This PC>Properties>Advanced System Settings>Environment Variables>New>Variable Name: JAVA_HOME>Variable Value: [YOUR JDK Path, Mine was "C:\Program Files\Java\jdk1.8.0_221"]
- In Unity 3D, press
Edit > Preferences > External Tools and fill in the JDK path (Mine was "C:\Program Files\Java\jdk1.8.0_221")
. - Also, in the same pop-up, edit SDK Path. (Get it from
Android Studio > SDK Manager > Android SDK > Android SDK Location
.) - If needed, restart your computer for changes to take effect.
来源:https://stackoverflow.com/questions/54358107/gradle-could-not-determine-java-version-from-11-0-2