我也在Windows的命令行上遇到相同的问题,它显示了相同的提示。
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. `compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.`
检查JDK location
在Project Structure
。
在Android Studio中打开:File
>>Project Structure
查看JDK位置是否指向您的JDK 1.8目录。
它看起来像
JDK Location
C:\Program Files\Java\jdk1.8.0_91
我已经为JDK设置了正确的位置。
检查java版本
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)
检查gradle版本
.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版本应为1.8。为了解决这个问题,我们可以在gradle.property加入gradle.properties
在.gradle
目录中的HOME_DIRECTORY
一组org.gradle.java.home=/path_to_jdk_directory
。对我来说,就像:
org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_91
要验证其设置是否正确,我们可以执行gradle build
任务。
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:
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: