IntelliJ/Gradle Could not determine java version from '11.0.1' - java

I'm running a Linux Ubuntu 18 OS. Installed jdk in a custom local directory.
Normally, IntelliJ recommends that you use the default gradle wrapper. But in my case, I want to be able to change the Gradle Version on the fly whenever it's due for an update.
If you use IntelliJ with Gradle, and you bump into the following error:
Could not determine java version from '11.0.1'

If you use IntelliJ
Checks:
Navigate to:
File >> Settings >> Build, Execution, Deployment >> Build Tools >> Gradle.
Alongside Gradle JVM:
make sure you select the correct version of Java.
Navigate to:
Right-Click 'Project Root Directory' & Select Open Module Settings. Project Structure windows shows-up. Make sure your JDK home path is added to the Platform Settings >> SDKs : JDK home path
Still, on the same window Project Structure, select correct SDK relevant to your project under
Project Settings >> Modules : Module SDK
Fix/Solution:
Nvavigate to & open: gradle/wrapper/gradle-wrapper.properties & update the distributionUrl version to the latest version.
In my case (at the time of this post), my older version was:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
And my latest version is:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
As shown below:
In your build.gradle file make sure you set:
sourceCompatibility = 11

If you are using the latest version of intellijIdea.
In my case, 2019.1 -version
Delete the directory idea's jdk
then RESTART idea.
for detail see this pic
Hope this is working for you !
In chinese:
(If you can't read chinese,you needn't to read this.All you need to know have typed above already)
如果你是用最新版本的intellijidea.由于intellijidea默认安装了11的java。而且就算你输入java -verison,告诉你是java8,在ide里面也配置了java 8 idea还是告诉你这个错误。
只有通过删除idea自己下载java11版本,可以解决这个问题。直接删除应用包下的jdk文件夹,重启idea就可以。如下图。

Your gradle is too old for that JDK, upgrade your gradle or downgrade you JDK

I noticed a subtlety in the way you download the IDE from jetbains.com
You probably want JBR 8 and not JBR 11. Also, make sure your JDK is setup properly with jbsdk bintray downloader plugin.

I recently upgraded my Ubantu to 18 from 16. After that I am facing this issue. Problem was during ubantu upgrade java is automatically upgraded to 11 from 8. Hence getting this error. You can simply downgrade jdk using this to solve this. Works for me.

Reintalling Intellij Worked for me.
You need to uninstall first before reinstall. While uninstalling, ensure to select option to delete older cache and settings

check , maybe you have 2 times gradle in path

MODIFY default Boot JDK
OPEN the Action Dialog
SEARCH : switch boot jdk
SELECT the JDK installed by you rather than the intellij default
RESTART intellij idea
IGNORE this popup at right-bottom on IDE
HOPE this solution is work for you .

Related

How to change the Gradle version?

I would like to change the Gradle version to 3.5.1 according to the project version received from git using this eclipse.
So I changed the editing path for the system environment variable, but if you enter 'gradle -v' in cmd, only 4.4 appears.
I looked for various solutions on the Internet, but it didn't work out.
How can I change the version?
And how can I erase the existing version 4.4 completely? I tried to erase it, but it kept popping up even if I deleted all the related files.
gradle -v:
One of the easiest way to change the gradle version is using sdkman. Install the required version you want and change whenever you want. Then hit
sdk install gradle <versionId>
sdk use gradle <versionId>
To check the list of versions installed
sdk list gradle
First, you need to know where Gradle is installed on your device. You can type where gradle in your terminal and the path will pop up.
Then, after you deleted the old version, go to the download page to download version 3.5.1. After download, follow the instructions in Installing manually in the Gradle installation guide.
Make sure that the old version is not included in your environment variables. If so, remove the old version and add the new one.
You can check Windows path variable by typing echo %PATH% in CMD.
Using Gradle Wrapper
To quote the manual:
If your existing Gradle-based build uses the Gradle Wrapper, you can easily upgrade by running the wrapper task, specifying the desired Gradle version:
./gradlew wrapper --gradle-version=7.4.2 --distribution-type=bin

How can I switch java verisons in intelliJ?

I'm using the linux beta installation on my chrome-book, and I'm trying to set up a project to use the jdk version 1.8. I previously had a project set up that uses jdk 1.11, and now it seems that even though the current project is configured to use jdk 1.8 in project settings etc, the maven installation used by intellij is still configured to use jdk 1.11. When I run java -version and mvn -verison in the intelliJ terminal, java 11 turns up. I tried changing the maven settings as well, but whenever I try to mvn compile and install, I get the following error:
/usr/lib/jvm/jdk1.8.0_271/bin/java: 1: /usr/lib/jvm/jdk1.8.0_271/bin/java: Syntax error: "(" unexpected
I can't figure out why this is happening, but it must be the fact that maven thinks this is java 11, when it's java 8. Does anyone know how to fix this?
CTRL-ALT-SHIFT-S / Project / Project SDK - you can choose existing or add configure another one
It turns out I had downloaded jdk-8u271-linux-arm64.tar.gz instead of jdk-8u271-linux-x64.tar.gz, which is why the code wasn't recognized after installing the jdk. Apparently the two are designed for different CPU architectures, and arm is for mobile devices, and wasn't compatible with my chromebook.

General error during semantic analysis: Unsupported class file major version 57

I'm trying to setup libgdx for a desktop game and when I try to generate the project I have this error and the build fails.
I've the latest versions of Java(13.0.2) and Gradle(6.6), both set as environment variables in the path. Can somebody help me?
The error looks like this:
Could not compile settings file 'C:\Users\noemi\Desktop\Test\settings.gradle'.
> startup failed:
General error during semantic analysis: Unsupported class file major version 57
java.lang.IllegalArgumentException: Unsupported class file major version 57
This is not a LibGDX issue. Gradle 5 is incompatible with Java 13. You either need to update Gradle (the wrapped version in your project) to Gradle 6 or later, or you need to use a lower version of the JRE.
To update the wrapped gradle, go to gradle/wrapper/gradle-wrapper-properties in your project and update the version number. I'm using 6.1.1.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
If you have an older LibGDX project, you might have to modify the build.gradle file in the android module to be compatible with Gradle 6. You can copy-paste to replace the copyAndroidNatives task with the one here.
startup failed:
General error during semantic analysis: Unsupported class file major version 61
how to fix this react native issues
JAVA JDK 17
Go to the android/ directory of your react-native project
Create a file called local.properties with this line:
sdk.dir=C:\Android\sdk
GOTO
android\gradle\wrapper\gradle-wrapper.properties
CHANGE
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
TO
distributionUrl=https://services.gradle.org/distributions/gradle-7.3-all.zip
GOTO
android\gradle.properties
add this line
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
This problem occurred when I run my old Flutter project that I coded 2 years ago. I think with Android project will also fix in the same way. I'm use MacOS and Android Studio Bumblebee.
First, need to move to the android folder and check gradle version:
cd android
./gradlew --version
It show Gradle version 6.7.1 and you need attention to the JVM line, and my JDK version is 15.0.2. It is too new for this project. So you must to downgrading from open jdk version to old version or upgrade Gradle version in gradle/wrapper/gradle-wrapper.properties to new version.
If you downgrade JDK version, you can download from this. In my case, I downgraded from Java SE 15 to Java SE 11.
After I open Android of Flutter project
Go to Preferences->Build, Execution, Deployment → Build Tools → Gradle → and choose JDK version 11.
Go to Build -> Clean Project -> Rebuild Project.
Go to Terminal run java --version, if it still show JE version 15 then You must set JAVA_HOME before.
You only need to add the following to your .bash_profile or .zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home
Save and go to android folder and run again
./gradlew --version
It will show JDK version 11 correct.
Finally, run flutter run.
If you're using eclipse, go to
Eclipse > Preferences > Gradle
Update Java home to point to Java home location
I have downgraded gradle file thats why this error happens so finally I have to change Gradle wrapper file From
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
Check gradle version and bundle version using the following link
Link https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
If you want to upgrade android/gradle/build.gradle change dependencies classpath 'com.android.tools.build:gradle:[latest version]'

Getting error when trying to run new project in Android Studio 2.2.1

I just updated to Android Studio 2.2.1 for Mac. Then I updated the JDK to version 8. Tried to start a new project and run it. I got the following error:
Error:(1, 1) A problem occurred evaluating project ':app'.
java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
I also tried going back to JDK version 7 as it says on google site that JDK 8 is unstable for Mac. still got the same error.
Check your android build tools dependencies. In your build.gradle if its something like:
classpath "com.android.tools.build:gradle:+"
It has likely downloaded the alpha of 2.2 and that can cause the error you are seeing.
Try
classpath "com.android.tools.build:gradle:2.1.0"
If you are already using the right build tools version but keep getting this error, maybe one of the third party Android libraries you are using is causing the problem due to the same reason. You can force the dependency version to be used (including transitive) by changing
classpath "com.android.tools.build:gradle:2.1.0"
to
classpath('com.android.tools.build:gradle:2.1.0') {
force = true
}
Documentation: gist and official gradle docs.
I was also facing same problem. I upgraded Android Studio and as it forced to But we need to configure same in App Settings as well.
You can try to update JAVA_HOME to point to JDK 8 location.
In my case, I've updated Android studio project's SDK settings, changed java version in my PATH env variable, but still this error occured. Only updating JAVA_HOME helped me.
I was also facing the same problem. I upgraded Android Studio and as it forced to install JDK 8, downloaded and installed this as well. But we need to configure same in App Settings as well.
Select Project [Right click on the app module] -> Open Module Settings -> Select SDK Location from Left Menu - > Configured correct JDK Version i.e removed the old version and updated path of JDK. Save.
Sync Project.
Problem solved!
EDIT: Elaborated Project word.
If you are on Jenkins, check Java version in Jenkins->Manage Jenkins->Global Tool Configuration->JDK
I had to update mine to JDK 8.
I had same error in 2.3 beta 1 ,
Fixed as follow :
Download latest java jdk
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
In Android Studio , go to File > Project Structure > SDK Location > select JDK Location path to point to the new jdk installed (Ex: C:\Program Files\Java\jdk1.8.0_111 )
Done !
Ufff, I changed like everything I was able to find to jdk 8 and still no result but then I found Gradle settings in Intellij (preferences > gradle > GradleJVM) and it was ofc wrong, changed that and woala.
I meet the problem too, but I have changed nothing before it's happening. I think google is purposely. Google is trying to use openJDK instead of JDK because of the lawsuit between google and oracle. So, in the new version 2.2.0 of android, we found that there are some new files in the installed folder:
android studio 2.1 files
android studio 2.2 files
Then, I think we have two method to fix it:
Change the JDK environment variable of your OS.
Just click menu File --> Project Structure, choose Use embedded JDK (recommended). I chose this way and it work.
Good luck...
I had a same problem what is work for me is that .
Go
*File>Settings>(on the panel left)Build,Execution,Deployment . then click on Gradle
There is option to Update Gradle. Click on that it will time 3 to 4min and after that error gone.
The simplest way is to update Android Studio to v2.2.3, it includes a fix of JDK8:
Bug fix for a JDK8/Kotlin compiler + dx issue (issue 227729)
It's solved my problem.

Intellij build after gradle refresh fails on wrong java version

I am using Gradle with intellij.
I refresh Gradle and then I rebuild my project.
I get the following
Notice the first line - Using:javac 1.8.0_65
But I get the error that I should use -source7 or higher.
I also set the following at the settings
(With all of the inner modules are set to project sdk (1.8))
But I still can't rebuild or compile without this error.
Any suggestions?
(obviously i deleted all my classes and jars and then Gradle refreshed and rebuild project)
Same issue; got it solved with the following:
Go to: File / Settings / Build,Execution,Deployment / Build Tools /
Gradle / Gradle JVM
Then choose: Use JAVA_HOME
As of your second screen, make sure that all your modules are using the project default SDK, like in the screen below. The module setting may somehow be set to point older java version.
I had this problem while trying to build Android Studio. I kept getting
Tools need to be compiled with Java 1.8, you are using Java 11
Everything in the Intellij global and "Project Structure" settings was set to Java 1.8 so I couldn't figure out what was going on. For whatever reason, what ended up working was going to Build, Execution, Deployment > Build > Gradle and selecting the Amazon corretto version of Java 1.8 as installed by sdkman. This is baffling since I'd already tried selecting two other options for Gradle JVM that said 1.8 and both of those still resulted in the same error message as a result of Java 11 being used.
I finally resolved this issue for myself. I'm on Windows and it turns out the order in which the JDKs are listed in the Windows environment variable matter, and overrode what IDEA had set.
Although my project has JDK11 listed everywhere, JDK17 was still being used. I was able to finally resolve this issue by moving their ordering to list JDK11 first.
before I swapped the env var order
after (hurray!)

Categories