【flutter填坑】Android Gradle plugin requires Java 11 to run

Flutter項目在對Android12進行適配時候,修改了SDK,build tools等相關(guān)工具版本后,會要求使用Java11進行編譯。
問題是,在更新了jdk后,依然會提示requires Java 11 to run

What went wrong:
A problem occurred evaluating project ':app'.
> 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`.

問題的原因在于,flutter使用的jdk是flutter doctor -v中顯示的位置

在命令行執(zhí)行flutter doctor -v
輸出結(jié)果中:
Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    ? Android SDK at /Users/caoxun/Library/Android/sdk
    ? Platform android-31, build-tools 31.0.0
    ? Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    //只有這里顯示是java 11才有效。如果這里是1.8jdk,那么別的地方配置是對flutter無效的。
    ? Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    //省略

其中的Java binary at才是指向flutter使用的jdk,它可能與系統(tǒng)中配置的JAVA_HOME并不是同一個路徑。

對于使用jenkins等服務器打包腳本的情況來說,問題也是同樣的。服務器上可能有多個jdk配置,但真正對flutter生效的依然是flutter doctor -v中顯示的路徑位置。所以需要對它進行更新或配置。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容