Flutter: Difference between revisions

From NixOS Wiki
imported>IVeryStronglyDislikeMondays
No edit summary
imported>Onny
(Add Flutter development notes)
Line 1: Line 1:
===How do I package my Flutter app with nix?===
 
== Development ==
 
Create following <code>flake.nix</code> in a new project directory
 
{{file|/etc/nixos/flake.nix|nix|<nowiki>
{
description = "Flutter 3.0.4";
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/23.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 = "30.0.3";
      androidComposition = pkgs.androidenv.composeAndroidPackages {
        buildToolsVersions = [ buildToolsVersion "28.0.3" ];
        platformVersions = [ "31" "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
            jdk11
          ];
        };
    });
}
</nowiki>}}
 
Run following commands to start a new demo project and run the "hello world" application
 
<syntaxhighlight lang="console">
# flutter create my_app
# cd my_app
# flutter run
</syntaxhighlight>
 
== Packaging ==
 
Use [https://github.com/NixOS/nixpkgs/blob/cfe96dbfce8bd62dcd4a8ad62cb79dec140b1a62/pkgs/development/compilers/flutter/flutter.nix#L168 buildFlutterApplication from nixpkgs].
Use [https://github.com/NixOS/nixpkgs/blob/cfe96dbfce8bd62dcd4a8ad62cb79dec140b1a62/pkgs/development/compilers/flutter/flutter.nix#L168 buildFlutterApplication from nixpkgs].


The [https://github.com/orgs/NixOS/teams/flutter team working on flutter in nixpkgs] maintains several pieces of infrastructure related to the cause. The documentation is lacking as of now, but there are plans to improve it.
== See also ==
 
* The [https://github.com/orgs/NixOS/teams/flutter team working on flutter in nixpkgs] maintains several pieces of infrastructure related to the cause. The documentation is lacking as of now, but there are plans to improve it.

Revision as of 16:21, 17 June 2023

Development

Create following flake.nix in a new project directory

/etc/nixos/flake.nix
{
description = "Flutter 3.0.4";
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/23.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 = "30.0.3";
      androidComposition = pkgs.androidenv.composeAndroidPackages {
        buildToolsVersions = [ buildToolsVersion "28.0.3" ];
        platformVersions = [ "31" "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
            jdk11
          ];
        };
    });
}

Run following commands to start a new demo project and run the "hello world" application

# flutter create my_app
# cd my_app
# flutter run

Packaging

Use buildFlutterApplication from nixpkgs.

See also

  • The team working on flutter in nixpkgs maintains several pieces of infrastructure related to the cause. The documentation is lacking as of now, but there are plans to improve it.