admin管理员组

文章数量:1129219

When using flutter build apk, gradle throw an error due to a failure while using JDK 8...

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':unifiedpush_android:compileDebugKotlin'.
> Provisioned toolchain '$HOME/.gradle/jdks/adoptium-8-x64-hotspot-linux/jdk8u432-b06' could not be probed.

The jdk folder is present and readable by all.

I tried modifying android/app/build.gradle to override flutter JDK config defaults:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

...
}

But gradle still throw the same JDK 8 error. How can I define the JDK version used by gradle?


Here are more information about my environment:

flake.nix:

{
  description = "Flutter environment";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          config.permittedInsecurePackages = [
            "olm-3.2.16"
          ];
        };
        androidEnv = pkgs.androidenv.override { licenseAccepted = true; };
        androidComposition = androidEnvposeAndroidPackages {
          ## Details about default values: .nix
          #
          buildToolsVersions = [ "30.0.3" ];
          platformVersions = [ "31" "32" "33" "34" ];
          cmakeVersions = [ "3.18.1" ];
          includeNDK = true;
          ndkVersion = "23.1.7779620";
          useGoogleAPIs = true;
          extraLicenses = [
            "android-googletv-license"
            "android-sdk-arm-dbt-license"
            "android-sdk-license"
            "android-sdk-preview-license"
            "google-gdk-license"
            "intel-android-extra-license"
            "intel-android-sysimage-license"
            "mips-android-sysimage-license"            ];
        };
        androidSdk = androidComposition.androidsdk;
      in
      {
        devShell = with pkgs; mkShell rec {
          ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
          ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
          CHROME_EXECUTABLE = "google-chrome-stable";
          JAVA_HOME = jdk17.home;
          FLUTTER_ROOT = flutter324;
          DART_ROOT = "${flutter324}/bin/cache/dart-sdk";
          GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/30.0.3/aapt2";
          QT_QPA_PLATFORM = "wayland;xcb";
          buildInputs = [
            androidSdk
            android-tools
            android-udev-rules
            flutter324
            gradle
            jdk17
          ];
          # Globally installed packages, which are installed through `dart pub global activate package_name`,
          # are located in the `$PUB_CACHE/bin` directory.
          shellHook = ''
            if [ -z "$PUB_CACHE" ]; then
              export PATH="$PATH:$HOME/.pub-cache/bin"
            else
              export PATH="$PATH:$PUB_CACHE/bin"
            fi

            flutter doctor -v
          '';
        };
      }
    );
}

When using flutter build apk, gradle throw an error due to a failure while using JDK 8...

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':unifiedpush_android:compileDebugKotlin'.
> Provisioned toolchain '$HOME/.gradle/jdks/adoptium-8-x64-hotspot-linux/jdk8u432-b06' could not be probed.

The jdk folder is present and readable by all.

I tried modifying android/app/build.gradle to override flutter JDK config defaults:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

...
}

But gradle still throw the same JDK 8 error. How can I define the JDK version used by gradle?


Here are more information about my environment:

flake.nix:

{
  description = "Flutter environment";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          config.permittedInsecurePackages = [
            "olm-3.2.16"
          ];
        };
        androidEnv = pkgs.androidenv.override { licenseAccepted = true; };
        androidComposition = androidEnv.composeAndroidPackages {
          ## Details about default values: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/mobile/androidenv/compose-android-packages.nix
          #
          buildToolsVersions = [ "30.0.3" ];
          platformVersions = [ "31" "32" "33" "34" ];
          cmakeVersions = [ "3.18.1" ];
          includeNDK = true;
          ndkVersion = "23.1.7779620";
          useGoogleAPIs = true;
          extraLicenses = [
            "android-googletv-license"
            "android-sdk-arm-dbt-license"
            "android-sdk-license"
            "android-sdk-preview-license"
            "google-gdk-license"
            "intel-android-extra-license"
            "intel-android-sysimage-license"
            "mips-android-sysimage-license"            ];
        };
        androidSdk = androidComposition.androidsdk;
      in
      {
        devShell = with pkgs; mkShell rec {
          ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
          ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
          CHROME_EXECUTABLE = "google-chrome-stable";
          JAVA_HOME = jdk17.home;
          FLUTTER_ROOT = flutter324;
          DART_ROOT = "${flutter324}/bin/cache/dart-sdk";
          GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/30.0.3/aapt2";
          QT_QPA_PLATFORM = "wayland;xcb";
          buildInputs = [
            androidSdk
            android-tools
            android-udev-rules
            flutter324
            gradle
            jdk17
          ];
          # Globally installed packages, which are installed through `dart pub global activate package_name`,
          # are located in the `$PUB_CACHE/bin` directory.
          shellHook = ''
            if [ -z "$PUB_CACHE" ]; then
              export PATH="$PATH:$HOME/.pub-cache/bin"
            else
              export PATH="$PATH:$PUB_CACHE/bin"
            fi

            flutter doctor -v
          '';
        };
      }
    );
}
Share Improve this question asked Jan 8 at 13:33 McFlyMcFly 232 bronze badges 2
  • adding toolchain definition in android/app/build.gradle doesn't work... same error – McFly Commented Jan 9 at 13:58
  • ERRATUM: adding java.toolchain.languageVersion = 17 triggers the exact same error, but version 11 or 18 are triggering an issue with an 11 or 18 version that could not be probbed – McFly Commented Jan 9 at 14:39
Add a comment  | 

1 Answer 1

Reset to default 0

Found a solution by adding to $HOME/.gradle/gradle.properties:

org.gradle.java.installations.paths=$jdk_8_path,$jdk_17_path

I am 50/50 on this approach as these paths are not static on a Nix installations. But it has the benefit of not modifying the project gradle.properties; hence preventing any build issue on other build platform

If someone has a better idea, I'd be glad to hear out!


my final flake looks like:

{
  description = "Flutter environment";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          config.permittedInsecurePackages = [
            "olm-3.2.16"
          ];
        };
        androidEnv = pkgs.androidenv.override { licenseAccepted = true; };
        androidComposition = androidEnv.composeAndroidPackages {
          ## Details about default values: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/mobile/androidenv/compose-android-packages.nix
          #
          buildToolsVersions = [ "30.0.3" "35.0.0" ];
          platformVersions = [ "31" "32" "33" "34" ];
          cmakeVersions = [ "3.18.1" ];
          includeNDK = true;
          ndkVersion = "23.1.7779620";
          useGoogleAPIs = true;
          extraLicenses = [
            "android-googletv-license"
            "android-sdk-arm-dbt-license"
            "android-sdk-license"
            "android-sdk-preview-license"
            "google-gdk-license"
            "intel-android-extra-license"
            "intel-android-sysimage-license"
            "mips-android-sysimage-license"
          ];
        };
        androidSdk = androidComposition.androidsdk;
      in
      {
        devShell = with pkgs; mkShell rec {
          ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
          ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
          JAVA_HOME = jdk17.home;
          JAVA_8_HOME = jdk8.home;
          JAVA_17_HOME = jdk17.home;
          FLUTTER_ROOT = flutter324;
          DART_ROOT = "${flutter324}/bin/cache/dart-sdk";
          GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/35.0.0/aapt2";
          QT_QPA_PLATFORM = "wayland;xcb"; # emulator related: try using wayland, otherwise fall back to X
          # NB: due to the emulator's bundled qt version, it currently does not start with QT_QPA_PLATFORM="wayland".
          # Maybe one day this will be supported.
          buildInputs = [
            ## General needs
            flutter324

            ## Android target
            androidSdk
            jdk17
            jdk8  # for gradle sake...
          ];
          # Globally installed packages, which are installed through `dart pub global activate package_name`,
          # are located in the `$PUB_CACHE/bin` directory.
          shellHook = ''
            if [ -z "$PUB_CACHE" ]; then
              export PATH="$PATH:$HOME/.pub-cache/bin"
            else
              export PATH="$PATH:$PUB_CACHE/bin"
            fi

            flutter doctor -v

            ## Just to please Gradle with a JDK8
            echo
            echo
            echo "Please Make Sure That: '$HOME/.gradle/gradle.properties' contains:"
            echo "org.gradle.java.installations.paths=$JAVA_8_HOME,$JAVA_17_HOME"
            echo
            echo
          '';
        };
      }
    );
}

本文标签: Flutter on Nixos flakenix for android apk targetStack Overflow