Azure build error: "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8"

Azure build error: "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8"

azure devOps 中构建 Flutter 应用程序时,我收到此错误:

Build file 'D:\a\s\android\app\build.gradle' line: 24

* 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`.

我已经尝试过,这些解决方案:

...

compileOptions {

sourceCompatibility JavaVersion.VERSION_11

    targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_11.toString()
}

还有其他解决方案,但我的错误没有解决。顺便说一句,我很容易 运行 应用程序和构建 apk,在我的本地 mac 上没有任何错误,但是当我推送我的代码时,Azure 给出了这些构建错误。

通过在 azure-pipelines.yml 文件中添加以下行解决了我的错误:

steps:
 - task: JavaToolInstaller@0
    inputs:
      versionSpec: '11'
      jdkArchitectureOption: 'x64'
      jdkSourceOption: 'PreInstalled'