升级 Android Studio 4.2 Task:app:compileDebugJavaWithJavac FAILED
解决办法(macOS)
Terminal中执行命令
./gradlew compileDebugJavaWithJavac --stacktrace
最终定位到错误,java JDK 环境没有找到导致。
开始解决问题,查看已安装的jdk版本,终端运行命令:
/usr/libexec/java_home -V
可见安装了两个版本,然后终端运行命令:java -version
默认使用版本,需要把Project Structure->SDK Location替换成默认JDK版本,操作如下:
Android Studio 状态栏 图标进入Project Structure->SDK Location JDK location
选择安装JDK版本地址即可,点击Apply,点击OK
最好是在Terminal中执行命令 ./gradlew clean
完成。
Android Studio 4.2
Build #AI-202.7660.26.42.7322048, built on April 29, 2021
Runtime version: 11.0.8+10-b944.6916264 x86_64
VM: OpenJDK 64-Bit Server VM by N/A
macOS 10.16
GC: G1 Young Generation, G1 Old Generation
Memory: 3072M
Cores: 8
Registry: external.system.auto.import.disabled=true, ide.balloon.shadow.size=0
Non-Bundled Plugins: cn.olange.rule, GsonFormatPlus, com.alibaba.p3c.smartfox, com.thoughtworks.gauge, com.notime.intellijPlugin.backgroundImagePlus, eu.inmite.android.plugin.selectorchapek, info.dong4j.idea.plugin.markdown.image.kit, net.vektah.codeglance, org.jetbrains.kotlin, com.mistamek.drawablepreview.drawable-preview