This is a guide for anyone looking to run flutter apps on a physical device on nix os.
I’ve been struggling for about a month to run flutter apps on an android device, as far as I’m concerned this is a relatively new issue and will get fixed once the stable channel (23.05) updates it’s flutter package.
Firstly, enable adb in your configuration file and add yourself to the adb users
{
programs.adb.enable = true;
users.users.<your-user>.extraGroups = ["adbusers"];
}
Now you may use the example flake at: Flutter - NixOS Wiki as a reference, but change the nixpkgs input url to point to nixpkgs-unstable, change whatever attributes of the androidenv package you need to change: Nixpkgs 24.05 manual | Nix & NixOS, but keep the 30.0.3 tools version
And add this enviroment variable to your shell
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/31.0.0/aapt2";
You should point to whatever build tools version you are using
My flake looks like this, for reference
{
description = "Flutter 3.0.4";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
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 = [ "31.0.0" buildToolsVersion "28.0.3" ];
platformVersions = [ "33" "28" ];
abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
};
androidSdk = androidComposition.androidsdk;
in
{
devShell =
with pkgs; mkShell rec {
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/31.0.0/aapt2";
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
buildInputs = [
flutter
androidSdk
jdk11
];
};
});
}
Don’t forget to run
flutter clean
rm ~/.cache/flutter
rm ~/.gradle
In case you’ve tried to build before