Flutter: Difference between revisions

imported>Jmarmstrong1207
m Add reference to android wiki page
imported>Jmarmstrong1207
Add more to the flake.nix to show you can use preconfigured androidSDKs. Add alternatives to making a dev shell.
Line 5: Line 5:
== Development ==
== Development ==


Create following <code>flake.nix</code> in a new project directory
The easiest way is to install Android Studio by adding <code>pkgs.androidstudio</code> to your list of packages in configuration.nix.
 
If you prefer [[Vscode|VSCode]], you can create a [[Development environment with nix-shell|dev-shell]] with the packages "jdk", "flutter", "sdkmanager", and a preferred android sdk such as the preconfigured one "androidenv.androidPkgs_9_0.androidsdk" (mentioned in the Android wiki page). Add other packages if missing any.
 
 
Below is an example [[Flakes|flake.nix]] for creating a dev shell. Create following <code>flake.nix</code> in a new project directory


{{file|flake.nix|nix|<nowiki>
{{file|flake.nix|nix|<nowiki>
Line 38: Line 43:
           buildInputs = [
           buildInputs = [
             flutter
             flutter
             androidSdk
            sdkmanager
             androidSdk # The customized SDK that we've made above
            jdk17
          ];
        };
    });
}
</nowiki>}}
 
If you don't want to customize the android sdk, you can instead use the predefined packages, as mentioned [https://nixos.org/manual/nixpkgs/unstable/#using-predefined-android-package-compositions in this section on the manual], such as <code>androidenv.androidPkgs_9_0.androidsdk</code>:
 
{{file|flake.nix|nix|<nowiki>
{
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;
        };
      };
    in
    {
      devShell =
        with pkgs; mkShell rec {
          ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
          buildInputs = [
            flutter
            sdkmanager
            androidenv.androidPkgs_9_0.androidsdk
             jdk17
             jdk17
           ];
           ];
Line 45: Line 86:
}
}
</nowiki>}}
</nowiki>}}


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