NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.05k stars 14.08k forks source link

Flutter app build error, Cmake PkgConfig::GTK and graphite2 include missing. #341147

Open MROvaiz opened 1 month ago

MROvaiz commented 1 month ago

Describe the bug

Error while running flutter run in unstable nixpkgs

[mro@nixbin:~/github/mrovaiz/flutter/my_app]$ flutter run
Launching lib/main.dart on Linux in debug mode...
CMake Error in CMakeLists.txt:
  Imported target "PkgConfig::GTK" includes non-existent path

    "/nix/store/bbp2rgd41n030a1wrr1k8ci7p41w82db-graphite2-1.3.14/include"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

CMake Generate step failed.  Build files cannot be regenerated correctly.
Building Linux application...                                           
Error: Unable to generate build files

Steps To Reproduce

Steps to reproduce the behavior:

  1. add environment pkg flutter.
  2. new folder flutter create my_app.
  3. run flutter run inside my_app.
  4. you will receive above error.

Expected behavior

App should be build and show the linux app or web.

Additional context

/nix/store/bbp2rgd41n030a1wrr1k8ci7p41w82db-graphite2-1.3.14 folder exist, but no include inside graphite2. this issue was also raise in forums nixos-forum stackoverflow

Notify maintainers

@RossComputerGuy

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[mro@nixbin:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.49, NixOS, 24.11 (Vicuna), 24.11.20240906.574d1ea`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - nixpkgs: `/nix/store/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source`

Add a :+1: reaction to issues you find important.

RossComputerGuy commented 1 month ago

/nix/store/bbp2rgd41n030a1wrr1k8ci7p41w82db-graphite2-1.3.14 folder exist, but no include inside graphite2. this issue was also raise in forums

What is in the graphite2 directory?

CC @NixOS/flutter

MROvaiz commented 1 month ago

@RossComputerGuy

[mro@nixbin:~]$ ls -alh /nix/store/bbp2rgd41n030a1wrr1k8ci7p41w82db-graphite2-1.3.14
total 4.8M
dr-xr-xr-x    5 root root   4.0K Jan  1  1970 .
drwxrwxr-t 5402 root nixbld 4.8M Sep 11 10:10 ..
dr-xr-xr-x    2 root root   4.0K Jan  1  1970 bin
dr-xr-xr-x    2 root root   4.0K Jan  1  1970 lib
dr-xr-xr-x    3 root root   4.0K Jan  1  1970 share
RossComputerGuy commented 1 month ago

Hmm, you might need to try flutter run with verbose and share the log.

MROvaiz commented 1 month ago

flutter run with verbose

[mro@nixbin:~/github/mrovaiz/flutter/my_app]$ flutter run --verbose
[  +24 ms] Unable to locate an Android SDK.
[  +76 ms] Skipping pub get: version match.
[  +73 ms] Generating /home/mro/github/mrovaiz/flutter/my_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
[  +48 ms] No packages with native assets. Skipping native assets compilation.
[   +1 ms] Initializing file store
[   +2 ms] Skipping target: gen_localizations
[   +1 ms] gen_dart_plugin_registrant: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents:
/home/mro/github/mrovaiz/flutter/my_app/.dart_tool/package_config_subset}
[  +30 ms] gen_dart_plugin_registrant: Complete
[        ] Skipping target: _composite
[        ] complete
[   +2 ms] Launching lib/main.dart on Linux in debug mode...
[   +1 ms] /nix/store/wp7165dbyc8w8ng10qaxkfsrrr9rc5hs-flutter-wrapped-3.24.1-sdk-links/bin/cache/dart-sdk/bin/dartaotruntime
--disable-dart-dev
/nix/store/wp7165dbyc8w8ng10qaxkfsrrr9rc5hs-flutter-wrapped-3.24.1-sdk-links/bin/cache/dart-sdk/bin/snapshots/frontend_server_aot.dart.snaps
hot --sdk-root
/nix/store/wp7165dbyc8w8ng10qaxkfsrrr9rc5hs-flutter-wrapped-3.24.1-sdk-links/bin/cache/artifacts/engine/common/flutter_patched_sdk/
--incremental --target=flutter --experimental-emit-debug-metadata --output-dill /tmp/flutter_tools.OGPOOU/flutter_tool.VJQPGM/app.dill
--packages /home/mro/github/mrovaiz/flutter/my_app/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false
--enable-asserts --track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill build/cache.dill.track.dill
--verbosity=error --enable-experiment=alternative-invalidation-strategy
[   +9 ms] Building Linux application...
[   +3 ms] <- compile package:my_app/main.dart
[        ] executing: [build/linux/x64/debug/] cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DFLUTTER_TARGET_PLATFORM=linux-x64
/home/mro/github/mrovaiz/flutter/my_app/linux
[  +53 ms] -- Configuring done (0.0s)
[   +9 ms] CMake Error in CMakeLists.txt:
[   +1 ms]   Imported target "PkgConfig::GTK" includes non-existent path
[        ]     "/nix/store/bbp2rgd41n030a1wrr1k8ci7p41w82db-graphite2-1.3.14/include"
[        ]   in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:
[        ]   * The path was deleted, renamed, or moved to another location.
[        ]   * An install or uninstall procedure did not complete successfully.
[        ]   * The installation package was faulty and references files it does not
[        ]   provide.
[   +1 ms] -- Generating done (0.0s)
[   +1 ms] CMake Generate step failed.  Build files cannot be regenerated correctly.
[   +9 ms] Building Linux application... (completed in 77ms)
[+2525 ms] Error: Unable to generate build files
[        ] "flutter run" took 2,826ms.
[   +5 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:874:9)
           <asynchronous suspension>
           #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1408:27)
           <asynchronous suspension>
           #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #4      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:416:9)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:364:5)
           <asynchronous suspension>
           #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #10     main (package:flutter_tools/executable.dart:93:3)
           <asynchronous suspension>

[  +56 ms] ensureAnalyticsSent: 54ms
[        ] Running 2 shutdown hooks
[  +12 ms] Shutdown hooks complete
[  +69 ms] exiting with code 1

I also checked in project created where PkgConfig::GTK is present. linux/flutter/CMakeLists.txt and linux/CMakeLists.txt. flutter create my_app Please have a look, it might also be the project require some pkg related to gtk!

FlafyDev commented 1 month ago

This usually happens when using flutter from nix shell instead of creating a dev shell and nix developing into it

MROvaiz commented 1 month ago

This usually happens when using flutter from nix shell instead of creating a dev shell and nix developing into it

As i mentioned, i have added flutter in environment pkg in my config file.

{pkgs, ...}: {
  environment.systemPackages = with pkgs; [
    flutter
  ];
}

git-flutter-config-file

I want to develop for linux and web for now.

FlafyDev commented 1 month ago

Yeah, that may be the same bug I decribed. Try to make a devshell with flutter and nix developing into it. Maybe that'll work

MROvaiz commented 1 month ago

Yeah, that may be the same bug I decribed. Try to make a devshell with flutter and nix developing into it. Maybe that'll work

I have this, and still same error.

{
  description = "Flutter 3.13.x";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/23.11";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = {
    self,
    nixpkgs,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = import nixpkgs {
        inherit system;
        config = {
          allowUnfree = true;
        };
      };
    in {
      devShell = with pkgs;
        mkShell rec {
          buildInputs = [
            flutter
            jdk17
          ];
        };
    });
}

I don't want android development, only linux. Edit: I also tried with both example from nixos-flutter with android Both gives Same error, its related to linux.

MROvaiz commented 1 month ago

I want to add one more point, i have hyprland. is it also related to desktop manager? error for gtk?

RossComputerGuy commented 1 month ago

I want to add one more point, i have hyprland.

Very unrelated, Hyprland would have absolutely no effect here. Have you tried adding GTK 3 to the dev shell inputs?

Andyson007 commented 1 month ago

I had the same issue, and found this


{
description = "Flutter 3.13.x";
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/23.11";
  flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
  flake-utils.lib.eachDefaultSystem (system:
    let
      pkgs = import nixpkgs {
        inherit system;
        config = {
          android_sdk.accept_license = true;
          allowUnfree = true;
        };
      };
      buildToolsVersion = "34.0.0";
      androidComposition = pkgs.androidenv.composeAndroidPackages {
        buildToolsVersions = [ buildToolsVersion "30.0.3" ];
        platformVersions = [ "29" "30" "31" "32" "33" "34" "28" ];
        abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
      };
      androidSdk = androidComposition.androidsdk;
    in
    {
      devShell =
        with pkgs; mkShell rec {
          ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
          GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/34.0.0/aapt2";
          buildInputs = [
            flutter
            androidSdk
            jdk17
          ];
        };
    });
}``` which seems to work for me
medanisjbara commented 1 month ago

So this is indeed a bug ? I thought I'm just too stupid to do this correctly!

For anyone looking for a workaround, here's a temporary solution I have been using:

Should work with no problems, if you ignore the repetitive warning on the first run, which seems to only appear in the first run.

The warning is as follows

Package libpcre2-8 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpcre2-8.pc'
to the PKG_CONFIG_PATH environment variable

but does not seem to affect anything as far as I can tell.

MROvaiz commented 1 month ago

@medanisjbara Thanks alot. i have ignored first run error. on second try im getting GL error.

Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           
✓ Built build/linux/x64/debug/bundle/my_app
(my_app:30109): Gtk-WARNING **: 15:50:35.262: Theme directory apps@2x/22 of theme WhiteSur has no size field
(my_app:30109): Gtk-WARNING **: 15:50:35.262: Theme directory apps@2x/32 of theme WhiteSur has no size field
(my_app:30109): Gtk-WARNING **: 15:50:35.262: Theme directory preferences@2x/22 of theme WhiteSur has no size field
(my_app:30109): Gdk-CRITICAL **: 15:50:35.292: gdk_gl_context_make_current: assertion 'GDK_IS_GL_CONTEXT (context)' failed
** (my_app:30109): WARNING **: 15:50:35.292: Failed to initialize GLArea: No GL implementation is available

New Config for nix develop:

{
  description = "Flutter 3.13.x";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/24.05";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = {
    self,
    nixpkgs,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = import nixpkgs {
        inherit system;
        config = {
          android_sdk.accept_license = true;
          allowUnfree = true;
        };
      };
      buildToolsVersion = "34.0.0";
      androidComposition = pkgs.androidenv.composeAndroidPackages {
        buildToolsVersions = [buildToolsVersion "28.0.3"];
        platformVersions = ["34" "28"];
        abiVersions = ["armeabi-v7a" "arm64-v8a"];
      };
      androidSdk = androidComposition.androidsdk;
    in {
      devShell = with pkgs;
        mkShell rec {
          ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
          buildInputs = [
            flutter
            androidSdk # The customized SDK that we've made above
            jdk17
            pkg-config
            gtk3
          ];
        };
    });
}

334430 Duplicate?!

Edit: Aim is to build linux app

emanueljg commented 1 month ago

I ran into the same error and managed to solve it by adding pkg-config and gtk3 to buildInputs, just as suggested above. As a bonus, I've finally compiled a list of all other packages needed to stop that "one-time nagging" mentioned above:

  buildInputs = [
    # emulator hwdecode
    vulkan-loader 
    libGL        

    # build shell hook
    pkg-config

    # needed to not crash
    gtk3

    # fixes nagging
    pcre2.dev
    util-linux.dev
    libselinux
    libsepol
    libthai
    libdatrie
    xorg.libXdmcp
    xorg.libXtst
    lerc.dev
    libxkbcommon
    libepoxy
  ];

This smells like a bug though, you shouldn't need to do all this.

MROvaiz commented 1 month ago

tried with adding extra pkgs from above, same error: related to GL

(my_app:9861): Gtk-WARNING **: 18:48:03.893: Theme directory apps@2x/22 of theme WhiteSur has no size field
(my_app:9861): Gtk-WARNING **: 18:48:03.893: Theme directory apps@2x/32 of theme WhiteSur has no size field
(my_app:9861): Gtk-WARNING **: 18:48:03.893: Theme directory preferences@2x/22 of theme WhiteSur has no size field
(my_app:9861): Gdk-CRITICAL **: 18:48:03.930: gdk_gl_context_make_current: assertion 'GDK_IS_GL_CONTEXT (context)' failed
** (my_app:9861): WARNING **: 18:48:03.930: Failed to initialize GLArea: No GL implementation is available
** (my_app:9861): CRITICAL **: 18:48:11.806: void fl_keyboard_manager_sync_modifier_if_needed(FlKeyboardManager *, guint, double): assertion 'FL_IS_KEYBOARD_MANAGER(self)' failed
hakan-demirli commented 6 days ago

Adding pkg-config and gtk3 does solve the issue however you need to first reset the build cache by deleting the ./build dir. Otherwise, the issue persists.