gradle Flutter Run的NixOs问题

dly7yett  于 2023-10-19  发布在  Flutter
关注(0)|答案(1)|浏览(155)

我在nixOS上,试图启动一个flutter项目。当我点击flutter run时,出现以下错误。

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-gradle-plugin', version: '1.0.0']
> A problem occurred configuring project ':gradle'.
   > Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
      > Failed to create parent directory '/nix/store/lbi43bsi63zvp7wjgswsp1vjrg4pv9b2-flutter-3.13.4-unwrapped/packages/flutter_tools/gradle/.gradle' when creating directory '/nix/store/lbi43bsi63zvp7wjgswsp1vjrg4pv9b2-flutter-3.13.4-unwrapped/packages/flutter_tools/gradle/.gradle/buildOutputCleanup'

有没有人知道这个问题,并知道如何解决它?我知道/nix/store中的所有内容都是只读的,但这应该可以工作。

z31licg0

z31licg01#

我遇到了类似的Gradle错误。最后,我成功地使用这个nix develop和这个flake在NixOS上构建了带有Flutter的.apk

{
  description = "moxplatform";
  inputs = {
    # nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixpkgs.url = "github:NixOS/nixpkgs/23.05";
    flake-utils.url = "github:numtide/flake-utils";
    android-nixpkgs.url = "github:tadfisher/android-nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils, android-nixpkgs }: flake-utils.lib.eachDefaultSystem (system: let
    pkgs = import nixpkgs {
      inherit system;
      config = {
        android_sdk.accept_license = true;
        allowUnfree = true;
      };
    };
    # Everything to make Flutter happy
    sdk = android-nixpkgs.sdk.${system} (sdkPkgs: with sdkPkgs; [
      cmdline-tools-latest
      build-tools-30-0-3
      build-tools-33-0-2
      build-tools-34-0-0
      platform-tools
      emulator
      patcher-v4
      platforms-android-30
      platforms-android-31
      platforms-android-33
    ]);
    pinnedJDK = pkgs.jdk17;
  in {
    devShell = pkgs.mkShell {
      buildInputs = with pkgs; [
        # Android
        pinnedJDK
        sdk

        # Flutter
        flutter dart

        # Code hygiene
          gitlint

        # Flutter dependencies for linux desktop
        atk
        cairo
        clang
        cmake
        epoxy
        gdk-pixbuf
        glib
        gtk3
        harfbuzz
        ninja
        pango
        pcre
        pkg-config
        xorg.libX11
        xorg.xorgproto
      ];

      # Make Flutter build on desktop
      CPATH = "${pkgs.xorg.libX11.dev}/include:${pkgs.xorg.xorgproto}/include";
      LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ atk cairo epoxy gdk-pixbuf glib gtk3 harfbuzz pango ];
      
      ANDROID_HOME = "${sdk}/share/android-sdk";
      ANDROID_SDK_ROOT = "${sdk}/share/android-sdk";
      JAVA_HOME = pinnedJDK;

      # Fix an issue with Flutter using an older version of aapt2, which does not know
      # an used parameter.
      GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${sdk}/share/android-sdk/build-tools/34.0.0/aapt2";
    };
  });
}

相关问题