Azure 构建错误:“Android Gradle 插件需要 Java 11 才能运行。您当前正在使用 Java 1.8”

M K*_*imi 10 java build azure build.gradle flutter

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

Build file 'D:\a\1\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`.
Run Code Online (Sandbox Code Playgroud)

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

  • 创建jitpack.yml具有价值的文件- openjdk11
  • 将以下行添加到块app/build.gradle内的文件中android {}

...

compileOptions {

sourceCompatibility JavaVersion.VERSION_11

    targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_11.toString()
}
Run Code Online (Sandbox Code Playgroud)

还有其他解决方案,但我的错误没有解决。顺便说一句,我可以轻松地在 Mac 上本地运行应用程序并构建 apk,没有任何错误,但是当我推送代码时,Azure 会给出这些构建错误。

M K*_*imi 24

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

steps:
 - task: JavaToolInstaller@0
    inputs:
      versionSpec: '11'
      jdkArchitectureOption: 'x64'
      jdkSourceOption: 'PreInstalled'
Run Code Online (Sandbox Code Playgroud)