'android-24' requires JDK 1.8 or later to compile - java

I use Android Studio and recently got the error:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.
But I have JDK 1.8 installed already:
:\Users..>java -version
java version "1.8.0_91" Java(TM) SE Runtime
Environment (build 1.8.0_91-b15) Java HotSpot(TM) 64-Bit Server VM
(build 25.91-b15, mixed mode)
How to fix it? Thanks

In Android Studio open:
File > Project Structure > see if JDK location points to your JDK 1.8 directory.
Note: you can use compileSdkVersion 24

I have a same problem for days. I found a solution which worked from me on Windows. (I also set environment variables, but don't know whether it's needed.)
Add these lines to build.gradle file:
android {
...
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
Source: https://code.google.com/p/android/issues/detail?id=203850

I installed latest jdk but it was using the older one until I did this:
app rt-click >> module settings >> sdk location >> (old jdk path)
Replace the old JDK path with your new jdk path.
Works like a charm now :)

Just an FYI I had this error with an Ionic project. All the commands came back pointing to the correct JDK and JAVA_HOME was set correctly.
There was an entry in my PATH to JDK 1.7\bin, replacing that with the 1.8\bin fixed it for me.

I was also running into the same issue from the command line on my Mac, but the answer was that JAVA_HOME was getting overridden. To track down where it is getting overridden first check java from the command line:
$ java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
Then check which version of Java that Gradle is using:
$ gradle -version
------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------
Build time: 2016-04-25 04:10:10 UTC
Build number: none
Revision: 3b427b1481e46232107303c90be7b05079b05b1c
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_92 (Oracle Corporation 25.92-b14)
OS: Mac OS X 10.11.5 x86_64
At this point, I still hadn't found the source of the problem. Did a little digging, and found that it was indeed overridden in my gradle.properties file even though it was showing Java 8 when I executed gradle -version:
org.gradle.daemon=true
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
org.gradle.jvmargs=-XX:MaxPermSize=512m -XX:-UseSplitVerifier -Xms512m -Xmx6144m
To fix, I just deleted the java.home line from gradle.properties. Hopefully this helps if anyone else is running into the same issue from the command line.

In Android Studio open:
File > Project Structure > SDK Location > Select jdk1.8.0_101.jdk > Home

I was also running into the same issue from the command line on my Windows, it shows the same hint.
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. `compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.`
check JDK location in Project Structure.
In Android Studio open: File > Project Structure > see if JDK location
points to your JDK 1.8 directory.
It should look like
JDK Location
C:\Program Files\Java\jdk1.8.0_91
I already set the correct location to JDK.
check the java version
D:\AndroidSelfTrainingProject\CustomBuildIdDemo>java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
check the gradle version
.D:\AndroidSelfTrainingProject\CustomBuildIdDemo>gradle -v
------------------------------------------------------------
Gradle 2.10
------------------------------------------------------------
Build time: 2015-12-21 21:15:04 UTC
Build number: none
Revision: 276bdcded730f53aa8c11b479986aafa58e124a6
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_79 (Oracle Corporation 24.79-b02)
OS: Windows 7 6.1 amd64
JVM version should be 1.8.
To fix it, we can add in the gradle.property
In gradle.properties in the .gradle directory in your HOME_DIRECTORY set org.gradle.java.home=/path_to_jdk_directory. As for me, it is like:
org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_91
To verify if it is set right, we can make a gradle build task.
D:\AndroidSelfTrainingProject\CustomBuildIdDemo>gradle build
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon
: https://docs.gradle.org/2.10/userguide/gradle_daemon.html.
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html

On Windows 10, I first checked Project Structure and it pointed to an old 1.7 jdk. I closed Android Studio then renamed the old jdks (and jre libraries for consistency) leaving the newest 1.8 library alone. When I restarted Android Studio and attempted to build the application it asked me for the Java JDK library and I gave the path to the newest 1.8 JDK library. On my system it was C:\Program Files\Java\jdk1.8.0_112.

Related

Requirements check failed for JDK 1.8.x! Detected version: 3.0.0

I am trying to build a quasar cordova app for Android. when I run the command quasar dev -m cordova -T android I get the error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\myUserName\AppData\Local\Android\Sdk
(recommended setting)
ANDROID_HOME=C:\Users\myUserName\AppData\Local\Android\Sdk
(DEPRECATED) Requirements check failed for JDK 1.8.x! Detected
version: 3.0.0 Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH
environment variables.
App · Command "cordova" failed with exit code: 1 App · Updated
Cordova config.xml App · ⚠️ [FAIL] Cordova CLI has failed
It says I need JDK 1.8.x, but it detected 3.0.0. But I am pretty sure I have JDK 1.8 installed, when I run the bash shell command java -version I get:
Picked up JAVA_TOOL_OPTIONS: -Xmx3g -Xms2g java version "1.8.0_291" Java(TM) SE Runtime Environment (build 1.8.0_291-b10) Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)
at C:\Program Files\Java I have two folders:
jdk1.8.0_291 and jre.18.0_291
my JAVA_HOME environment variable is set to C:\Program Files\Java\jdk1.8.0_291
I have no idea why I can't get the app to build. Please help!
I had the environment variable JAVA_TOOL_OPTIONS set to something. After clearing the variable and trying again, everything worked. I read it may be due to the regex used by Execa failing to detect the correct version when using JAVA_TOOL_OPTIONS.
I had to remove "C:\Program Files\Common Files\Oracle\Java\javapath" as an entry in my PATH variables to get around this

Java 11 requirements check failed for JDK 1.8 or greater with Cordova

When I run ````cordova run android``` in the path of my project I get
Android Studio project detected
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '27.+' to /path/to/platforms/android/app/build.gradle
cordova-android-support-gradle-release: Wrote custom version '27.+' to /path/to/cordova-android-support-gradle-release/norsan-cordova-android-support-gradle-release.gradle
ANDROID_HOME=/usr/lib/android-sdk
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Requirements check failed for JDK 1.8 or greater
My version of Java
$ java --version
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04, mixed mode, sharing)
My version of javac
$ javac --version
javac 11.0.5
My version of Cordova
$ cordova --version
9.0.0 (cordova-lib#9.0.1)
My version of Node
$ node --version
v10.15.2
My version of Nodejs
$ nodejs --version
v10.15.2
My version of NPM
$ npm --version
5.8.0
My version of Gradle
$ gradle -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/java/groovy-all.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------
Build time: 2012-12-21 00:00:00 UTC
Revision: none
Groovy: 2.4.16
Ant: Apache Ant(TM) version 1.10.5 compiled on March 28 2019
JVM: 11.0.5 (Private Build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04)
OS: Linux 5.0.0-38-generic amd64
I found that android-studio --version didn't do anything but silently wait, but when I open the program through the graphical user interface I see that the version is 3.6.1.
My version of androidsdk is Unknown... Not sure why.
$ androidsdk --version
SDK_ROOT=/home/galen/snap/androidsdk/21/AndroidSDK
Picked up _JAVA_OPTIONS: -Duser.home=/home/galen/snap/androidsdk/21
Unknown version
My version of Ubuntu
$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=19.04
DISTRIB_CODENAME=disco
DISTRIB_DESCRIPTION="Ubuntu 19.04"
NAME="Ubuntu"
VERSION="19.04 (Disco Dingo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 19.04"
VERSION_ID="19.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=disco
UBUNTU_CODENAME=disco
My understanding is that Java 11 comes later than JDK 1.8, so why does the requirements check fail? And, how do I fix this requirements check failure?
Update:
Java 11 is supported for cordova 10+ which allows for the same minimum Android versions as cordova 9. This should now be the preferred solution.
Original answer (for reference):
You are correct that Java 11 is more recent than JDK 1.8 and that it should work in theory.
However, cordova explicitly requires JDK 1.8 still:
Android doesn’t use oracles java but their own implementation, which at the moment is like java 8. So this is an android limitation, not something cordova can fix.
(cf. also issue 510)
Their development guide explicitly mentions JDK 1.8 as well:
Java Development Kit (JDK)
Install Java Development Kit (JDK) 8.
So the fix for now would be installing JDK 1.8 (if you go for Oracle note their recently changed license terms). You may watch PR 928 that attempts to ease that restriction, though.
The problem here is that the command does not respect JAVA_HOME variable (you need to set this to Java 8 as well)
As someone already mentioned, the bump from 8 to 11 is massive. Many libraries that were in Java 8 are moved out in Java 11, so while Java itself is backward compatible, the included libraries are not.
What works for me is to set JAVA_HOME to JDK8
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
AND I need to configure system wide java and javac settings with commands
sudo update-alternatives --config java
sudo update-alternatives --config javac

Android Studio: Could not determine Java version using executable C:\Program Files\Java\jdk-10\bin\java.exe

I wanted to use my JDK 10 in my Android Studio. I went to Files > Project Structure and specified my JDK location:
C:\Program Files\Java\jdk-10
After I clicked 'OK', it showed me a Gradle sync failed message with an error:
Could not determine Java version using executable C:\Program Files\Java\jdk-10\bin\java.exe.
I've set the JAVA_HOME variable to my jdk and jre folder, and the path variable to C:\ProgramData\Oracle\Java\javapath but the problem still occurs.
I can also find the Java version with the command:
"C:\Program Files\Java\jdk-10\bin\java.exe" -version
which gives me the correct version:
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
Screenshot:
Versions:
OS: Windows 10 64-bit
Android Studio Version: 3.1.0.16
JDK Version: 10
it happen in android studio 3.2.0 when your import your project to new android studio you must use this build gradle or newer
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
}

java/lang/NoClassDefFoundError: java/lang/invoke/MethodHandle eclipse juno

Im running Eclipse Juno on Mac OSX 10.8.4, I tried to update my jdk to 1.7 when I run my Java App and I have this error:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/invoke/MethodHandle
if I run on terminal
java -version
I get this
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
for updating this I set on Eclipse
Window - Preferences - Java - Installed JREs - Duplicate
JRE home: /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
JRE name: Java SE 7 (MacOS X Default)
also changed compiler level
Window - Preferences - Java - Compiler - Compiler compilance level: 1.7
also added next lines to /Users/myUser/.bash_profile:
VA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME=$VA_HOME
export CLASSPATH=$VA_HOME
export PATH=$PATH:$JAVA_HOME/bin
but still getting same error
Any help I'll appreciate
in your launch configuration, check that the right JRE System Library is on the Classpath
Have you added JAVA_HOME to your PATH? Usually you get this problem due to a bad installation of the SDK. Try
javac -version
From the command line and see if this differs to
java -version
And produces the same NoClassDefFoundError as above.
The most probable reason of java/lang/NoClassDefFoundError is that you have a jar in your classpath which references another jar which is missing in classpath. The referencing classes won't be initialized.
Now for your case, you upgraded to 1.7 which would have added dependencies. Make sure your classpath now refers to jdk/jre 1.7

Intellij IDEA using java7 compiler to compile when I have configured it to use Java6

I have set the Module SDK to 1.6
I have also set the Project SDK to 1.6
and I also change Java compiler options from setting to use java 6
but still it is using java 7 to compile. When I compile or run it gives following error
Using javac 1.7.0_11 to compile java sources
java: Errors occurred while compiling module 'SSLJava6'
Compilation completed with 1 error and 0 warnings in 1 sec
1 error
0 warnings
java: javacTask: source release 1.7 requires target release 1.7
Has anyone faced such problem before? What must be done?
Output of java -version
[aniket#localhost jndiProperties]$ java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
and my JAVA_HOME is also set to same.
Interesting.
Questions:
Check that c:\Users\$user\.IntelliJIdea12\config\options\jdk.table.xml has a reference to JDK6 only. This is what the file looks like for me:If there is a reference to a JDK 7 in there then delete the corresponding <jdk> element and restart Intellij.
I know that you have confirmed the java and javac path. Confirm the javac being used by writing a simple HelloWorld.java in a brand new Intellij project. If in the new project javac6 is used, then it's an issue with the old project configuration.
If there is a public JRE 7 lurking about, try un-installing it temporarily. After un-installation check that there is no cruft left behind in the Windows registry at HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
Check whether the build fails if you rename the JDK7 home dir. If so, try symlinking the JDK7 dir to point to the Java6 installation dir. In the windows world the following will work to do the symlink : mklink /J c:\Java7Home c:\ExistingJava6Home
Try setting your IDEA_JDK_64 environment variable to point to your java SDK you want intelliJ to use for example 'D:\Programs\Java\jdk1.9'.
I encountered this issue when installing the new java 9 early access jdk and trying to run it on intelliJ 15.
This fixed it on IntelliJ 16 EAP versions.

Categories

Resources