IntelliJ always builds for Java 1.7 - intellij-idea

I have my ANT configured to use a 1.6 JDK, my ENV variables JRE_HOME and JDK home both point to JDK6.
If I modify the JDK 6 folder name in my File explorer then my ANT build fails, cannot find JDK, so I know for sure it is using the correct JDK. However the generated clases are always compiled against java 1.7. Why i this? (My generated classes will only run on a 1.7 jre, I get version error if i run on a 1.6 JRE) All my project/module settings are pointing to 1.6 jdk.

Looks like not all of your Module/Project settings point to JDK 1.7 or you are using in-process javac option in Settings | Compiler while running IDEA under JDK 1.7.
Also check additional javac command line options, it should not contain options like -source 1.7 -target 1.7.

Related

Can not execute maven wrapper verify goal in IntelliJ IDEA 2021.2 [duplicate]

Background
I started my first project in android studio to get familiar with Android programming.
I am following this tutorial, in which
I created a new project Empty Activity, without any change
It is supposed to simulate a simple app that shows "Hello World" message
Problem Description
But every time I try to run and build (I want to emulator as of now), I get the following error message.
Unable to make field private final java.lang.String java.io.File.path accessible:
Unable to make field private final java.lang.String java.io.File.path
accessible: module java.base does not "opens java.io" to unnamed module #42760a00
Here is my config set-up:
Android Gradle plugin version: 4.2.1
Gradle Version: 7.0.1 (changed to fix another issue I had while syncing the Gradle ("Gradle sync failed: Unsupported class file major version 60") and based discussion on this forum as quoted below)
Andrey Dernov commented 14 Apr 2021 00:18 Please use Gradle 7.0 or JDK
less than 16 version for importgin and building the project (Settings
(Preferences on macOS) | Build, Execution, Deployment | Build Tools |
Gradle | Gradle JVM option).
JDK: 16.0.1
Any suggestion or idea?
The solution from GitHub has worked for me. It was no need to downgrade Java JDK. Just changed gradle version in gradle-wrapper properties to 7.1.1 (6.x does not support java 16), and adding the following line in gradle.properties:
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
You must be using a JDK version that is not supported by the Gradle Version.
( There is no need to downgrade )
1-Check your JDK Version from C:\Program Files\Java. In My Case, It's JDK-17.0.2
2-Check The Respective Gradle version for your JDK
https://docs.gradle.org/current/userguide/compatibility.html
3-Open gradle-wrapper.properties from .\android\gradle\wrapper\
and change the distributionUrl to your required gradle version
e.g. for JDK 17
distributionUrl = https\://services.gradle.org/distributions/gradle-7.3-all.zip
4-Open build.gradle from .\android\build.gradle
and change the plugin in the class path to the one according to your gradle version
e.g.
classpath("com.android.tools.build:gradle:4.2.2") for Gradle 6.7.1+
classpath("com.android.tools.build:gradle:7.0.0") for Gradle 7+
Check the Compatible Plugin for your Gradle version at
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
5-run npx react-native run-android
I think I found the solution.
If you are importing an old project you are likely to face this error.
Basically you made your old project with lower JDK versions and now you have higher JDK versions installed currently in your system.
You should avoid higher JDK versions for building older projects.
Basically Download JDK 8 (1.8) and install it.
change environment variable (write JDK 8 path to environment variable)
Then change your project structure and write JDK 8 path to JDK location.
invalidate caches and restart android studio.
build your project and it should work.
If you got the following error:
Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536
Then add the following dependency in your app.gradle file:
// multidex
implementation 'com.android.support:multidex:1.0.3'
then you need to enable multidex in your app.gradle file.
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.convenient.easymeasure"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
I found this discussion kind of related to my question.
But could not figure out how to pass JVM parameters in Android studio.
But, the error is gone after replacing JDK 16 by JDK 15.
Run Flutter doctor, if there´s an error indicating that the java bundled can´t be found (specially if you have Android Studio version Artic Fox), run this commands if using Mac:
cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
has worked for me in Macbook Air M1 Apple Silicon. you no need to downgrade or uninstall Java JDK.
in my case Just changed gradle version in gradle-wrapper.properties to 7.2
like this :
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
and adding the following line in gradle.properties:
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
related solution on github
This is a known issue when using Gson and reflection for parsing Json. Updating your Android Gradle Plugin version to 7.0.0+ and the error should go away.
For those having these issues with the latest Android Studio - Electric Eel version, and other canaries and preview releases, note that the bundled jre directory in the Android Studio installation folder is now renamed to jbr
(This answer came from eja's answer on this question.)
To resolve this, just create a sym link jre -> jbr and Flutter won't complain.
On Linux
cd ~/android-studio/ && ln -s jbr jre
Windows (check installation folder)
cd C:\Program Files\Android\Android Studio
mklink /D "jre" "jbr"
or
New-Item -ItemType SymbolicLink -Path .\jre -Target .\jbr
Mac OS
cd /Applications/Android\ Studio.app/Contents
ln -s jbr jre
Note that if you are running a preview release, the default installation directory might be different, e.g. on Linux it would be
~/android-studio-preview/
You must be using JDK-16, use the version below JDK-16, in my case, I downgrade to JDK-11 and it worked for me.
I downloaded 2 JDK jdk-17.0.1 and jdk-11.0.13 and add below line on gradle.properties
org.gradle.java.home=C\:\\Program Files (x86)\\Java\\jdk-11.0.13
Also go to Android Studio (Arctic Fox)-> Project Structure -> Gradle setting and choose JDK version
I was able to fix it by upgrading grade project settings using Android Studio which replaced
classpath("com.android.tools.build:gradle:4.2.2") with classpath('com.android.tools.build:gradle:7.0.3') in android/build.gradle
Had same problem with Flutter.
I uninstalled Android Studio and Android SDK and reinstalled everything and upgraded Flutter, without success.
Then I created a new Flutter project and copied the sources from the old one, and this time it worked.
Installing JDK 1.8.0 and setting JAVA_HOME path to JDK 1.8.0's folder in environment variables worked for me.
Just added from another solution
If you have later version installed, and your project is using older version. Don't forget to check in terminal which jdk is used.
In my case my project using JDK 15. And terminal using 18. So i uninstall the other version and leaving the proper version (in my mac, just delete another jdk directory in /Libray/Java/JavaVirtualMachine)
I had the same issue with a Flutter 2 project after updating Android Studio to electric eel. I was still able to build the android project, but flutter run on the Flutter project would cause this issue. lortschi's answer was the key, but it was missing one more entry to make it work, so my final gradle.properties looks like this now:
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 \
--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
android.useAndroidX=true
android.enableJetifier=true
I was very skeptical, but it worked.
Windows user:
Go to C:\Users\arpan.gradle\caches and delete all the gradle cache.
then,
Go to "C:\Program Files\Android\Android Studio" there you will see jbr and jre folder then copy the content of jbr and paste the content into jre folder.
ss:
and run flutter doctor again and run your App.
Check if JDK is installed or not configure your SDK also and try again
you can download JDKfrom Java SE
After I updated jdk to 18 then I got this error mention I the question. so I downgraded to jdk11. to install jdk11 please run this command I windows 10. choco install openjdk11. Hope it will fix your problem.
To run the above command you must have to install chocolatey and add it to path. chocolatey is dependency manager for windows 10. Here is link to guide
Here is the link https://community.chocolatey.org/packages/openjdk11

IntelliJ add Java 11

I need to add my installed Java 11 version to the project settings, because of this error (Error:java: invalid source release: 11).
When i go to project structure -> Project settings -> Project there it just shows Java 1.8.
When i try to add "java-11-openjdk-amd64" it fails with the reason "The selected directory points to a JRE, not a JDK.".
java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode)
The java application is available in the Java Runtime Environment (JRE). The fact that java is available in version 11 does not necessarily mean that the Java Development Kit (JDK) is also installed for version 11. However, IntelliJ needs the JDK which includes tools like the compiler javac.
In order to use Java 11 in IntelliJ, you need to install the Java 11 JDK.
For example on Ubuntu you can do that by executing:
sudo apt install openjdk-11-jdk

Netbeans installer issue with jdk 11

I downloaded and installed jdk 11 and am now trying to install netbeans 8.2. But i get an error which states "JAVA SE was not found on this computer.Make sure JDK is properly installed and run installer again. You can specify valid JDK location using --javahome installer argument."
I created a JAVA_HOME variable and set the value to "C:\Program Files\Java\jdk-11.0.1\bin" and set the same value for PATH variable as well.
How do i fix this?
You face a couple of issues:
NetBeans 8.2 requires JDK 8, and it will not work with any version of Java > 8.
NetBeans does not yet support JDK 11, though the release of a new version which does (NetBeans 10) is imminent.
The easiest approach would be to remove JDK 11 (unless you need it for other reasons apart from NetBeans), install Java 8 then reinstall NetBeans 8.2. It used to be possible to download NetBeans 8.2 bundled with Java 8, but if you try that now Oracle will just redirect you to the Apache NetBeans 9.0 web site.
There is a newer release of NetBeans than 8.2, Apache NetBeans 9.0. While it supports Java 9 and Java 10, it also does not support Java 11.
Updated to reflect that NetBeans 10 was released on December 27, 2018:
If you really want to use Java 11 with NetBeans you can download the latest Jenkins build of the beta version of NetBeans 10 at your own risk.
If you want to use Java 11 with NetBeans then download NetBeans 10.0. The download is a zip file and it works on all platforms.
Find netbeans.conf file in C:\Program Files\NetBeans 8.1 RC\etc.
In that atlas you'll find the netbeans_jdkhome. Set it accordingly.
You can specify the JDK to use by installing from the command line. So install a JDK 8 (e.g. Azul Zulu Open JDK 8) and then launch the netbeans installer:
netbeans-8.2-javaee-windows.exe --javahome "c:\Program Files\Zulu\zulu-8"
Once the installation starts, you will be asked which JDK to use for the IDE; make sure to choose your JDK 8 instead of the JDK 11. I have used this to install NetBeans 8.2RC successfully on Windows 10.

IntelliJ JDK not installed

I just installed intelliJ and tried to import an eclipse project. I have a jre installed but no jdk. It doesnt want to compile without a jdk. What am I doing wrong? Do I need one?
Yes, you need it. JRE required only to run java programs. JDK - for development.

java glassfish jdk 7 jre 6 version conflict

Downloaded JDK 7 from Oracle Java (comes w Glassfish) and installed on a Windows 7 machine.
In the shell, when I issue these commands:
javac -version
java -version
... I get two different versions. The compiler seems to be Java 7 but the JRE appears to be Java 6. Obviously this is a problem because programs compiled in Java 7 throw exceptions when run in Java 6 JRE.
Question 1: why does a JDK have different versions for the javac.exe compiler and the java.exe?
Question 2: how is it expected to be setup to work?
Question 1: why does a JDK have different versions for the javac.exe compiler and the java.exe?
It doesn't. You already have a Java 6 JRE installed and this is in your PATH before the JDK 7's bin directory. Remove the JRE 6 bin directory from your PATH.
Question 2: how is it expected to be setup to work?
Make sure the bin directory of your Java 7 JDK is in the PATH and not the Java 6 JRE bin directory.
See the JDK Installation Guide, especially the part Updating the PATH Environment Variable.
You need to check you JAVA_HOME environment variable and make sure it points to the correct JDK, then check the 'path' environment variable and make sure you don't have duplicate jre/jdk paths there.