最近(2021/10)更新完AndroidStudio後,發現新建立的專案都無法正常編譯執行,剛建好的新專案只要一執行就會跳出以下紅字錯誤訊息:
Build file 'C:\Users\xxxxxxx\Documents\MyApplication3\app\build.gradle' line: 2
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
上面是說Java的版本不正確,看來更新後萬年Java 1.8版本不能用了,需要用Java 11才能繼續執行。
網路上試了幾個方法,不過越搞越複雜,在這邊紀錄一下我的解法。
只要把專案設定中的Java改成Java 11以上即可。
進入File/Project Structure
左邊欄位選擇SDK Location,然後在右邊選擇Gradle Settings

在Gradle設定中,將下方的Gradle JDK設為11(如果沒有11可以選就選擇Download JDK自動下載)

然後再’Run APP’一次就搞定了!
-END-
發佈留言