Flutter: Difference between revisions

From NixOS Wiki
imported>ANicon111
m (added android dependencies for building)
imported>IVeryStronglyDislikeMondays
No edit summary
Line 1: Line 1:
== Developement enviroment ==
===How do I package my Flutter app with nix?===
 
Your best bet is [https://github.com/flafydev/dart-flutter-nix dart-flutter-nix].
To be able to build flutter apps, you need to add the platform-specific dependencies to your environment. This may be done by running <code>nix-shell</code> using a shell.nix configuration:
You can try nixpkgs's [mkFlutterApp https://github.com/NixOS/nixpkgs/blob/unstable/pkgs/development/compilers/flutter/flutter.nix#L165] too, but it is at the moment very broken:
 
https://github.com/NixOS/nixpkgs/issues/211606
<syntaxhighlight lang=nix>
{ pkgs ? import <nixpkgs> {} }:
let android-nixpkgs = (pkgs.callPackage (import (builtins.fetchGit {url = "https://github.com/tadfisher/android-nixpkgs.git";})) {channel = "stable";});
 
in pkgs.mkShell {
  buildInputs = with pkgs; [
    #basics
    flutter git
    #linux build
    at-spi2-core.dev clang cmake dbus.dev flutter gtk3 libdatrie libepoxy.dev util-linux.dev libselinux libsepol libthai libxkbcommon ninja pcre pcre2.dev pkg-config xorg.libXdmcp xorg.libXtst
    #android build
    (android-nixpkgs.sdk (sdkPkgs: with sdkPkgs; [cmdline-tools-latest build-tools-32-0-0 tools patcher-v4 platform-tools platforms-android-31 system-images-android-31-default-x86-64 emulator])) jdk8 unzip
    #web build
    chromium
  ];
  #declaring FLUTTER_ROOT
  FLUTTER_ROOT = pkgs.flutter;
  #libepoxy workaround
  LD_LIBRARY_PATH = "${pkgs.libepoxy}/lib";
  #web chrome and dart-sdk workaround
  CHROME_EXECUTABLE = "chromium";
  shellHook = ''
    if ! [ -d $HOME/.cache/flutter/ ]
    then
    mkdir $HOME/.cache/flutter/
    fi
    ln -f -s ${pkgs.flutter}/bin/cache/dart-sdk $HOME/.cache/flutter/
  '';
}
</syntaxhighlight>
 
This file uses the tool android-nixpkgs made by tadfisher to get all the android dependencies (be sure to change the package versions/branch to your needs; they can be found here: https://github.com/tadfisher/android-nixpkgs/tree/main/channels )
 
Also be sure to run <code>avdmanager create avd -n "Android" -k "system-images;android-31;default;x86_64"</code> to create an android emulator

Revision as of 15:01, 29 March 2023

How do I package my Flutter app with nix?

Your best bet is dart-flutter-nix. You can try nixpkgs's [mkFlutterApp https://github.com/NixOS/nixpkgs/blob/unstable/pkgs/development/compilers/flutter/flutter.nix#L165] too, but it is at the moment very broken: https://github.com/NixOS/nixpkgs/issues/211606