Flutter in VSCode does not see my Android device, but flutter from the terminal does

I am in the following situation:
I have a flake for flutter development.
It gets activated by direnv when I enter the project folder and performs the flutter setup.
After that, I run flutter create . to initialize the project.

I am including the flake and direnv files here.

flake.nix
  
  {
  description = "Flutter 3.0.4";
  inputs = {
    nixpkgs.url = "github:nanashi0x74/nixpkgs/flutter-3-0-0";
    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
            ];
          };
      });
  } 
  
  
flake.lock
  
  {
    "nodes": {
      "flake-utils": {
        "locked": {
          "lastModified": 1656928814,
          "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
          "owner": "numtide",
          "repo": "flake-utils",
          "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
          "type": "github"
        },
        "original": {
          "owner": "numtide",
          "repo": "flake-utils",
          "type": "github"
        }
      },
      "nixpkgs": {
        "locked": {
          "lastModified": 1657540956,
          "narHash": "sha256-ihGbOFWtAkENwxBE5kV/yWt2MncvW+BObLDsmxCLo/Q=",
          "owner": "nanashi0x74",
          "repo": "nixpkgs",
          "rev": "043de04db8a6b0391b3fefaaade160514d866946",
          "type": "github"
        },
        "original": {
          "owner": "nanashi0x74",
          "ref": "flutter-3-0-0",
          "repo": "nixpkgs",
          "type": "github"
        }
      },
      "root": {
        "inputs": {
          "flake-utils": "flake-utils",
          "nixpkgs": "nixpkgs"
        }
      }
    },
    "root": "root",
    "version": 7
  }
  
  
.envrc
  
  use flake
  
  

Now, I am developing for Android and flutter run works perfectly from the shell where direnv is active.
The only problem I have left is this one:
Visual Studio Code (codium to be precise) does not see my phone as connected: it says “No Device” in the status bar at the bottom.

I have installed both the official dart and flutter extensions (Dart-Code.dart-code and Dart-Code.flutter)

Running flutter doctor from the terminal (where direnv is active) gives me the following output (i.e., it correctly identifies the Android device):

Output from `flutter doctor` in the terminal where direnv is active
  
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 3.0.4, on NixOS 22.11 (Raccoon) 5.18.15, locale en_US.UTF-8)
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        ✗ cmdline-tools component is missing
          Run `path/to/sdkmanager --install "cmdline-tools;latest"`
          See https://developer.android.com/studio/command-line for more details.
        ✗ Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
    [✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
        ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
    [☠] Linux toolchain - develop for Linux desktop (the doctor check crashed)
        ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at
          https://github.com/flutter/flutter/issues.
        ✗ ProcessException: Failed to find "pkg-config" in the search path.
            Command: pkg-config 
    [!] Android Studio (not installed)
    [✓] Connected device (2 available)
    [✓] HTTP Host Availability
! Doctor found issues in 4 categories.
Output from `flutter doctor -v` in the terminal where direnv is active
  
  [ +119 ms] executing: uname -m
  [  +74 ms] Exit code 0 from: uname -m
  [        ] x86_64
  [  +11 ms] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git -c log.showSignature=false --git-dir .git log -n 1
  --pretty=format:%H
  [  +31 ms] Exit code 0 from: git -c log.showSignature=false --git-dir .git log -n 1 --pretty=format:%H
  [        ] 85684f9300908116a78138ea4c6036c35c9a1236
  [   +1 ms] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git --git-dir .git tag --points-at
  85684f9300908116a78138ea4c6036c35c9a1236
  [  +33 ms] Exit code 0 from: git --git-dir .git tag --points-at 85684f9300908116a78138ea4c6036c35c9a1236
  [        ] 3.0.4
  [  +19 ms] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git --git-dir .git rev-parse --abbrev-ref --symbolic @{u}
  [  +14 ms] Exit code 0 from: git --git-dir .git rev-parse --abbrev-ref --symbolic @{u}
  [        ] origin/stable
  [        ] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git --git-dir .git ls-remote --get-url origin
  [  +14 ms] Exit code 0 from: git --git-dir .git ls-remote --get-url origin
  [        ] https://github.com/flutter/flutter.git
  [ +122 ms] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git --git-dir .git rev-parse --abbrev-ref HEAD
  [   +9 ms] Exit code 0 from: git --git-dir .git rev-parse --abbrev-ref HEAD
  [        ] stable
  [ +112 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
  [   +7 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
  [  +99 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
  [        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
  [        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
  [        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
  [        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
  [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
  [        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
  [ +123 ms] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git --git-dir .git rev-parse --abbrev-ref HEAD
  [   +8 ms] Exit code 0 from: git --git-dir .git rev-parse --abbrev-ref HEAD
  [        ] stable
  [        ] Skipping request to fetchTags - on well known channel stable.
  [        ] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git --git-dir .git tag --points-at HEAD
  [  +26 ms] Exit code 0 from: git --git-dir .git tag --points-at HEAD
  [        ] 3.0.4
  [  +83 ms] executing: [/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/] git -c log.showSignature=false --git-dir .git log -n 1
  --pretty=format:%ar
  [  +17 ms] Exit code 0 from: git -c log.showSignature=false --git-dir .git log -n 1 --pretty=format:%ar
  [   +1 ms] 5 weeks ago
  [ +121 ms] executing: /nix/store/5sdq8zhi6cnf3wl6kjk4n3qrs6z9h1n7-androidsdk/libexec/android-sdk/platform-tools/adb devices -l
  [  +77 ms] [✓] Flutter (Channel stable, 3.0.4, on NixOS 22.11 (Raccoon) 5.18.15, locale en_US.UTF-8)
  [   +1 ms]     • Flutter version 3.0.4 at /nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped
  [        ]     • Upstream repository https://github.com/flutter/flutter.git
  [        ]     • Framework revision 85684f9300 (5 weeks ago), 2022-06-30 13:22:47 -0700
  [        ]     • Engine revision 6ba2af10bb
  [        ]     • Dart version 2.17.5
  [        ]     • DevTools version 2.12.2
  [  +98 ms] List of devices attached
            41425U8901U99526       device usb:1-1 product:SM-A505W model:SM_A505W device:SMA505W transport_id:1
  [  +11 ms] /nix/store/5sdq8zhi6cnf3wl6kjk4n3qrs6z9h1n7-androidsdk/libexec/android-sdk/platform-tools/adb -s 41425U8901U99526 shell getprop
  [ +185 ms] ro.hardware = hi6250
  [        ] ro.build.characteristics = default
  [   +9 ms] executing: /nix/store/5sdq8zhi6cnf3wl6kjk4n3qrs6z9h1n7-androidsdk/libexec/android-sdk/platform-tools/adb devices -l
  [  +25 ms] List of devices attached
            41425U8901U99526       device usb:1-1 product:SM-A505W model:SM_A505W device:SMA505W transport_id:1
  [  +62 ms] [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
  [        ]     • Android SDK at /nix/store/5sdq8zhi6cnf3wl6kjk4n3qrs6z9h1n7-androidsdk/libexec/android-sdk
  [   +1 ms]     ✗ cmdline-tools component is missing
  [        ]       Run `path/to/sdkmanager --install "cmdline-tools;latest"`
  [        ]       See https://developer.android.com/studio/command-line for more details.
  [        ]     ✗ Android license status unknown.
  [        ]       Run `flutter doctor --android-licenses` to accept the SDK licenses.
  [        ]       See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
  [   +4 ms] [✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
  [        ]     ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
  [   +1 ms] [☠] Linux toolchain - develop for Linux desktop (the doctor check crashed)
  [   +2 ms]     ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at
                  https://github.com/flutter/flutter/issues.
  [        ]     ✗ ProcessException: Failed to find "pkg-config" in the search path.
  [        ]         Command: pkg-config 
  [        ]     • #0      LocalProcessManager.run (package:process/src/interface/local_process_manager.dart:87:7)
  [        ]       #1      ErrorHandlingProcessManager.run. (package:flutter_tools/src/base/error_handling_io.dart:669:24)
  [        ]       #2      _run (package:flutter_tools/src/base/error_handling_io.dart:567:20)
  [        ]       #3      ErrorHandlingProcessManager.run (package:flutter_tools/src/base/error_handling_io.dart:668:12)
  [        ]       #4      LinuxDoctorValidator._libraryIsPresent (package:flutter_tools/src/linux/linux_doctor.dart:186:38)
  [        ]       #5      LinuxDoctorValidator.validate (package:flutter_tools/src/linux/linux_doctor.dart:145:20)
  [        ]       
  [        ]       #6      Future.any.onValue (dart:async/future.dart:611:5)
  [        ]       
  [   +1 ms] [!] Android Studio (not installed)
  [        ]     • Android Studio not found; download from https://developer.android.com/studio/index.html
  [        ]       (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
  [   +4 ms] [✓] Connected device (2 available)
  [        ]     • SM A505W (mobile) • 41425U8901U99526 • android-arm64 • Android 9 (API 28)
  [        ]     • Linux (desktop)  • linux            • linux-x64     • NixOS 22.11 (Raccoon) 5.18.15
  [+1028 ms] [✓] HTTP Host Availability
  [        ]     • All required HTTP hosts are available
  [        ] ! Doctor found issues in 4 categories.
  [  +19 ms] "flutter doctor" took 2,076ms.
  [  +50 ms] ensureAnalyticsSent: 43ms
  [   +1 ms] Running shutdown hooks
  [        ] Shutdown hooks complete
  [        ] exiting with code 0
  
  
Flutter daemon log (obtained by setting the dart.flutterDaemonLogFile option
  
!! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!

Dart Code extension: 3.44.0
Flutter extension: 3.44.0 (not activated)

App: VSCodium
Version: 1.69.2
Platform: linux

HTTP_PROXY: undefined
NO_PROXY: undefined

Logging Categories:
FlutterDaemon

Thu Aug 04 2022 [09:37:48 GMT+0200 (Central European Summer Time)] Log file started
[9:37:48 AM] [FlutterDaemon] [Info] Spawning /nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped/bin/flutter with args [“daemon”]
[9:37:48 AM] [FlutterDaemon] [Info] … in /nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped
[9:37:48 AM] [FlutterDaemon] [Info] … with {“toolEnv”:{“FLUTTER_HOST”:“VSCode”,“PUB_ENVIRONMENT”:“vscode.dart-code”}}
[9:37:48 AM] [FlutterDaemon] [Info] PID: 31555
[9:37:48 AM] [FlutterDaemon] [Info] ==> [{“id”:“1”,“method”:“emulator.getEmulators”}]
[9:37:50 AM] [FlutterDaemon] [Info] <== [{“event”:“daemon.connected”,“params”:{“version”:“0.6.1”,“pid”:31722}}]
[9:37:50 AM] [FlutterDaemon] [Info] ==> [{“id”:“2”,“method”:“device.enable”}]
[9:37:50 AM] [FlutterDaemon] [Info] <== [{“event”:“daemon.logMessage”,“params”:{“level”:“status”,“message”:“Starting device daemon…”}}]
[9:37:50 AM] [FlutterDaemon] [Info] <== [{“id”:“1”,“result”:}]
[9:37:50 AM] [FlutterDaemon] [Info] <== [{“id”:“2”}]
[9:37:54 AM] [FlutterDaemon] [Info] <== [{“event”:“device.added”,“params”:{“id”:“linux”,“name”:“Linux”,“platform”:“linux-x64”,“emulator”:false,“category”:“desktop”,“platformType”:“linux”,“ephemeral”:false,“emulatorId”:null,“sdk”:“NixOS 22.11 (Raccoon) 5.18.15”,“capabilities”:{“hotReload”:true,“hotRestart”:true,“screenshot”:false,“fastStart”:false,“flutterExit”:true,“hardwareRendering”:true,“startPaused”:true}}}]
[9:37:54 AM] [FlutterDaemon] [Info] ==> [{“id”:“3”,“method”:“daemon.getSupportedPlatforms”,“params”:{“projectRoot”:“/home/racoon/Projects/Flutter/Test1”}}]
[9:37:54 AM] [FlutterDaemon] [Info] <== [{“id”:“3”,“result”:{“platforms”:[“android”]}}]


While running flutter doctor through vs code’s command palette (ctrl+shift+p) does not see the Android device (sees only linux).

output from `Flutter: run flutter doctor` in vscode
  
  [flutter] flutter doctor -v
  [!] Flutter (Channel stable, 3.0.4, on NixOS 22.11 (Raccoon) 5.18.15, locale en_US.UTF-8)
      • Flutter version 3.0.4 at /nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped
      • Upstream repository https://github.com/flutter/flutter.git
      • Framework revision 85684f9300 (5 weeks ago), 2022-06-30 13:22:47 -0700
      • Engine revision 6ba2af10bb
      • Dart version 2.17.5
      • DevTools version 2.12.2
      ✗ Downloaded executables cannot execute on host.
        See https://github.com/flutter/flutter/issues/6207 for more information
        On Debian/Ubuntu/Mint: sudo apt-get install lib32stdc++6
        On Fedora: dnf install libstdc++.i686
        On Arch: pacman -S lib32-gcc-libs

[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: Download Android Studio & App Tools - Android Developers
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
flutter config --android-sdk to update to that location.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[:skull_and_crossbones:] Linux toolchain - develop for Linux desktop (the doctor check crashed)
✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at Issues · flutter/flutter · GitHub.
✗ ProcessException: Failed to find “pkg-config” in the search path.
Command: pkg-config
#0 LocalProcessManager.run (package:process/src/interface/local_process_manager.dart:87:7)
#1 ErrorHandlingProcessManager.run. (package:flutter_tools/src/base/error_handling_io.dart:669:24)
#2 _run (package:flutter_tools/src/base/error_handling_io.dart:567:20)
#3 ErrorHandlingProcessManager.run (package:flutter_tools/src/base/error_handling_io.dart:668:12)
#4 LinuxDoctorValidator._libraryIsPresent (package:flutter_tools/src/linux/linux_doctor.dart:186:38)
#5 LinuxDoctorValidator.validate (package:flutter_tools/src/linux/linux_doctor.dart:145:20)

#6 Future.any.onValue (dart:async/future.dart:611:5)

[!] Android Studio (not installed)
• Android Studio not found; download from Download Android Studio & App Tools - Android Developers
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (1 available)
• Linux (desktop) • linux • linux-x64 • NixOS 22.11 (Raccoon) 5.18.15

[✓] HTTP Host Availability
• All required HTTP hosts are available

! Doctor found issues in 5 categories.
exit code 0


I have adb enabled in my system-wide NixOS config with:
programs.adb.enable = true;
users.users.${config.username}.extraGroups = [ "adbusers" ];

Has anyone else experienced a similar problem or knows how to fix this?
I tried the workaround suggested here, but with no luck.
Looking at the outputs, I guess it may be because somehow vscode does not run the command adb devices -l, which does indeed list only my Android device.

Which exact vscode attribute did you install? The -fhs ones do only have limited access to hardware if I understand correctly, due to running in a chroot.

I installed codium via home-manager

programs.vscode = {
    enable = true;
    package = pkgs.vscodium;
    mutableExtensionsDir = false;
    userSettings = pkgs.lib.importJSON ./config/vscode/settings.json;
    extensions = [ ... ];
};

It looks to me like the main issue is it’s not finding the android sdk. Is the path set in the project android/local.properties? Does it show up in something like ps -C codium eww | grep ANDROID_SDK_ROOT?

Thank you for the reply

The path is indeed set in android/local.properties

Content of android/local.properties
sdk.dir=/nix/store/5sdq8zhi6cnf3wl6kjk4n3qrs6z9h1n7-androidsdk/libexec/android-sdk
flutter.sdk=/nix/store/gi3sf2xn0mshk5qsrrsdkdd51q0d47xv-flutter-3.0.4-unwrapped
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1

The command ps -C codium eww | grep ANDROID_SDK_ROOT instead gives me an empty output (from the same terminal in which flutter does list my Android device)

Finally!

I launched codium from inside the direnv shell and it does show the device :heart_eyes:.

The problem was the following:
NixOS does not install the android SDK in the default location (~/android/whatever), but instead in the nix store, as everything. Because of this, vscode/codium (and the flutter/dart extension therein) is only able to find it if we explicitly tell it using the ANDROID_SDK_ROOT environment variable.

Since direnv sets such variable only inside its shell (as it is supposed to do), we need to launch codium from inside the same shell.


Since I already documented all my trials and errors, I’ll include them here in case they are of interest to somebody.

My previous (failled) attempts at toubleshooting this.

Test 1

Did a test installing Flutter v2.10.1 from nixpkgs-unstable system-wide.

To do so, I added the following to my config

Things I added to my configuration.nix


{ pkgs, ... }:

let

buildToolsVersion = "30.0.3";

androidComposition = pkgs.androidenv.composeAndroidPackages {

buildToolsVersions = [ buildToolsVersion ];

platformVersions = [ "31" "28" ];

abiVersions = [ "armeabi-v7a" "arm64-v8a" ];

};

androidSdk = androidComposition.androidsdk;

in

{

nixpkgs.config = {

android_sdk.accept_license = true;

allowUnfree = true;

};

environment.sessionVariables = {

ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";

};

environment.systemPackages = with pkgs; [

flutter

androidSdk

jdk11

];

}




Then I rebuint my NixOS configuration and rebooted. Codium now detects the Android device without any problem and I can run Flutter apps.

Still, I’d like to understand and try to solve the problem in the flake.

The command ps -C codium eww | grep ANDROID_SDK_ROOT finds the ANDROID_SDK variable and the output is (truncated) ... ANDROID_SDK_ROOT=/nix/store/hbw00kq3cx305bj48i7dxq2x9h6j42ki-androidsdk/libexec/android-sdk ...

In local.properties, the sdk is set


sdk.dir=/nix/store/hbw00kq3cx305bj48i7dxq2x9h6j42ki-androidsdk/libexec/android-sdk

flutter.sdk=/nix/store/iw3szg43c1rgy68fkqqva7g02rbk027n-flutter-2.10.1-unwrapped

Test 2

My second test has been to remove the portion


environment.sessionVariables = {

ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";

};

from the system configuration, nixos-rebuild and reboot.

Codium still detects the Android device, even if the output of ps -C codium eww | grep ANDROID_SDK_ROOT now is empty.

The output from flutter doctor ran from codium’s palette is

Output from flutter doctor run in codium palette


[flutter] flutter doctor -v

Failed to find the latest git commit date: VersionCheckError: Command exited with code 128: git -c log.showSignature=false log -n 1 --pretty=format:%ad --date=iso

Standard out:

Standard error: fatal: detected dubious ownership in repository at '/nix/store/iw3szg43c1rgy68fkqqva7g02rbk027n-flutter-2.10.1-unwrapped'

To add an exception for this directory, call:

git config --global --add safe.directory /nix/store/iw3szg43c1rgy68fkqqva7g02rbk027n-flutter-2.10.1-unwrapped

Returning 1970-01-01 01:00:00.000 instead.

[!] Flutter (Channel unknown, 0.0.0-unknown, on NixOS 22.11 (Raccoon) 5.18.15, locale en_US.UTF-8)

• Flutter version 0.0.0-unknown at /nix/store/iw3szg43c1rgy68fkqqva7g02rbk027n-flutter-2.10.1-unwrapped

• Upstream repository unknown

• Framework revision (), 1970-01-01 01:00:00.000

• Engine revision ab46186b24

• Dart version 2.16.2

• DevTools version 2.9.2

✗ Downloaded executables cannot execute on host.

See https://github.com/flutter/flutter/issues/6207 for more information

On Debian/Ubuntu/Mint: sudo apt-get install lib32stdc++6

On Fedora: dnf install libstdc++.i686

On Arch: pacman -S lib32-gcc-libs

[✗] Android toolchain - develop for Android devices

• Android SDK at /nix/store/7q1gp3lbqpx3qkx8z7xdx8690skfdgq1-platform-tools-33.0.2/libexec/android-sdk

✗ cmdline-tools component is missing

Run `path/to/sdkmanager --install "cmdline-tools;latest"`

See https://developer.android.com/studio/command-line for more details.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)

! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[!] Android Studio (not installed)

• Android Studio not found; download from https://developer.android.com/studio/index.html

(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (1 available)

• SM A505W (mobile) • 41425U8901U99526 • android-arm64 • Android 9 (API 28)

[✓] HTTP Host Availability

• All required HTTP hosts are available

! Doctor found issues in 4 categories.

exit code 0



In summary, I see that codium is able to locate the android sdk if I install it globally (even if the ANDROID_SDK_ROOT environment variable is not set)

Test 3

In the third test, I removed the system-wide flutter, androidsdk and java packages (basically, I removed the config at the very beginning of this message) and went back to flutter in direnv.

Launched codium from the direnv shell where ANDROID_SDK_ROOT was set to a value (by direnv) and boom, codium saw my android device.

Epiphany!

Finally we have found the culprit! The sdk got installed in /nix/store/5sdq8zhi6cnf3wl6kjk4n3qrs6z9h1n7-androidsdk/libexec/android-sdk and the only way to make codium (and its extensions) aware of it was to invoke codium from inside the direnv shell. So simple now. Duh.

1 Like