android 24 requires jdk 1.8,'android-24' requires JDK 1.8 or later to compile

问题

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

回答1:

In Android Studio open:

File > Project Structure > see if JDK location points to your JDK 1.8 directory.

Note: you can use compileSdkVersion 24

回答2:

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

回答3:

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 :)

回答4:

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.

回答5:

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.

回答6:

In Android Studio open:

File > Project Structure > SDK Location > Select jdk1.8.0_101.jdk > Home

回答7:

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

回答8:

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.

来源:https://stackoverflow.com/questions/37933651/android-24-requires-jdk-1-8-or-later-to-compile

### 解决方案 当遇到 `maven-compiler-plugin` 版本与 Maven 版本不兼容的问题时,可以通过以下方法解决问题: #### 1. 验证当前使用的 Maven 版本 确认本地安装的 Maven 是否满足插件的要求。可以运行以下命令来查看当前的 Maven 版本: ```bash mvn -v ``` 如果显示的版本低于 3.6.3,则需要升级到更高版本。 #### 2. 升级 Maven 到最新版本 下载并安装最新的 Maven 版本(至少为 3.6.3)。可以从官方站点获取:[Apache Maven Downloads](https://maven.apache.org/download.cgi)[^3]。完成安装后重新验证版本号。 #### 3. 修改 `pom.xml` 中的插件配置 如果不希望更改全局 Maven 版本,也可以调整项目的 `pom.xml` 文件中的 `maven-compiler-plugin` 插件版本。例如,降级到更早支持的版本(如 3.8.1),修改如下: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> ``` #### 4. 使用工具链文件指定 JDK 和 Maven 的组合 通过创建一个名为 `toolchains.xml` 的文件,在其中定义所需的 Java 和 Maven 组合。将其放置于 `${user.home}/.m2/toolchains.xml` 或项目根目录下的 `.mvn/` 文件夹中。示例内容如下: ```xml <toolchains> <toolchain> <type>jdk</type> <provides> <version>1.8</version> <vendor>oracle</vendor> </provides> <configuration> <home>/path/to/jdk</home> </configuration> </toolchain> </toolchains> ``` #### 5. 清理构建缓存并重试 清理旧的依赖项和编译产物后再尝试重新构建项目: ```bash mvn clean install ``` --- ### 总结 上述解决方案提供了多种方式处理 `maven-compiler-plugin` 不兼容问题。推荐优先考虑 **验证和更新 Maven 版本** 或者 **调整插件版本至较低稳定版** 来快速修复此问题[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值