I use Android Studio and recently got the error:
Error:Execution failed for task \':app:compileDebugJavaWithJavac\'. compileSdkVersion \'android-24\' re
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