NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.48k stars 13.67k forks source link

Documentation: Flutter Flake #267263

Open dudozermaks opened 10 months ago

dudozermaks commented 10 months ago

Problem

Can't run flake from documentation

How to reproduce:

  1. Go to https://wiki.nixos.org/wiki/Flutter#Development.
  2. Create flake.nix with content as follows.
  3. Run nix develop.
  4. See this: error: The version 34.0.0 is missing in package build-tools. The only available versions are 17.0.0, 18.0.1, 18.1.0, 18.1.1, 19.0.0, ........ 33.0.2, 34.0.0-rc1, 34.0.0-rc2, 34.0.0-rc3, 34.0.0-rc4.

I Tried...

... To change

inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/23.05";
  flake-utils.url = "github:numtide/flake-utils";
};

to:

inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  flake-utils.url = "github:numtide/flake-utils";
};

this flake builds, then running

flutter create somename

cd somename

flutter build apk

FAILURE: Build failed with an exception.

* Where:
Build file '/somepath/somename/android/app/build.gradle' line: 4

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-gradle-plugin', version: '1.0.0']
> A problem occurred configuring project ':gradle'.
   > Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
      > Failed to create parent directory '/nix/store/jc032k4vpl3p5l37bl65a2649flqqybh-flutter-3.13.8-unwrapped/packages/flutter_tools/gradle/.gradle' when creating directory '/nix/store/jc032k4vpl3p5l37bl65a2649flqqybh-flutter-3.13.8-unwrapped/packages/flutter_tools/gradle/.gradle/buildOutputCleanup'

Error is the same as when installing flutter and providing it with dependencies for Android build.

Proposal

Write valid flake.nix. I'm brand new to flutter and flakes, but I have some things to say.

Maybe we should provide user not only with the flake.nix, but with flake.lock too? Like this: "If flake does not run, try removing flake.lock and replacing with this (link to valid flake.lock file)"

Also, there is a working flake by user called racoon, both with .nix and .lock files, which I'm now using. This flake is quite outdated, but maybe we should include this one in docs?

Checklist

ghost commented 10 months ago

Hi everyone!

I think I found a quickfix, I shared it here: https://discourse.nixos.org/t/problem-building-flutter-app-for-android/35593.

Have a nice day!

dudozermaks commented 9 months ago

@johynpapin Can you please share your flake.lock file? I do exactly what you say, but flutter wants SDK version older, than in flake.nix. When I change it, it doesn't work too...

ghost commented 9 months ago

Is the nixpkgs section enough?

    "nixpkgs": {
      "locked": {
        "lastModified": 1700538105,
        "narHash": "sha256-uZhOCmwv8VupEmPZm3erbr9XXmyg7K67Ul3+Rx2XMe0=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "51a01a7e5515b469886c120e38db325c96694c2f",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
dudozermaks commented 9 months ago

After some modifying of flake.nix it does work, yay! I will post my solution later, after some refactoring.

dudozermaks commented 9 months ago

Alright, solution to this problem is:

  1. If you have existing project, go there. If not, skip this step

  2. Create flake.nix file, with content below

  3. Run nix develop to enter the development shell

  4. If you have no project created (you skipped step 1), then run flutter create projectname and cd into that project

  5. Modify your android/app/build.gradle (I provided an example how it should look after modifications below)

    1. Remove this at the top:
      plugins {
          id "com.android.application"
          id "kotlin-android"
          id "dev.flutter.flutter-gradle-plugin"
      } 
    2. Go to:
      android {
          namespace "com.example.experemental"
          compileSdkVersion flutter.compileSdkVersion
          ndkVersion flutter.ndkVersion
          ...
      }
    3. Right before android { ... insert:

      def flutterRoot = localProperties.getProperty('flutter.sdk')
      if (flutterRoot == null) {
          throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
      }
      
      apply plugin: 'com.android.application'
      apply plugin: 'kotlin-android'
      apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
  6. Run flutter build apk or flutter build apk --debug

  7. If none of that works, try to remove flake.lock file in this directory, and replace it with attached one.

flake.nix ```nix { description = "Flutter 3.13.x"; inputs = { nixpkgs.url = "nixpkgs/nixos-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; }; }; # special version for aapt2 (usually latest avalible) buildToolsVersionForAapt2 = "34.0.0-rc4"; # Installing android sdk androidComposition = pkgs.androidenv.composeAndroidPackages { # Installing both version for aapt2 and version that flutter wants buildToolsVersions = [ buildToolsVersionForAapt2 "30.0.3" ]; platformVersions = [ "33" "28" ]; abiVersions = [ "armeabi-v7a" "arm64-v8a" ]; includeEmulator = true; emulatorVersion = "34.1.9"; }; androidSdk = androidComposition.androidsdk; in { devShell = with pkgs; mkShell rec { ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk"; # specify gradle the aapt2 executable GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/34.0.0-rc4/aapt2"; buildInputs = [ flutter androidSdk jdk17 xorg.libX11 ]; }; }); } ```
flake.lock ``` { "nodes": { "flake-utils": { "inputs": { "systems": "systems" }, "locked": { "lastModified": 1694529238, "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { "owner": "numtide", "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { "lastModified": 1701068326, "narHash": "sha256-vmMceA+q6hG1yrjb+MP8T0YFDQIrW3bl45e7z24IEts=", "owner": "NixOS", "repo": "nixpkgs", "rev": "8cfef6986adfb599ba379ae53c9f5631ecd2fd9c", "type": "github" }, "original": { "id": "nixpkgs", "ref": "nixos-unstable", "type": "indirect" } }, "root": { "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } }, "systems": { "locked": { "lastModified": 1681028828, "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "owner": "nix-systems", "repo": "default", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { "owner": "nix-systems", "repo": "default", "type": "github" } } }, "root": "root", "version": 7 } ```
build.gradle (EXAMPLE ONLY, you should modify it yourself!!!) ### Before ``` plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" } def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } android { namespace "com.example.experemental" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.experemental" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies {} ``` ### After ``` def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { namespace "com.example.experemental" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.experemental" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies {} ```
hatch01 commented 9 months ago

@dudozermaks I created an empty dir, copied you flake.nix and flake.lock. run flutter create . modified the android/app/build.gradle according to what you've written. but when I build I get this issue :

flutter build apk                

Checking the license for package Android SDK Platform 33 in /nix/store/ygxvbchm0q2dilfakgvy6srjvkxma26p-androidsdk/libexec/android-sdk/licenses
License for package Android SDK Platform 33 accepted.
Preparing "Install Android SDK Platform 33 (revision: 3)".
Warning: Failed to read or create install properties file.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:lintVitalReportRelease'.
> Failed to install the following SDK components:
      platforms;android-33 Android SDK Platform 33
  The SDK directory is not writable (/nix/store/ygxvbchm0q2dilfakgvy6srjvkxma26p-androidsdk/libexec/android-sdk)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Running Gradle task 'assembleRelease'...                         1 791ms
Gradle task assembleRelease failed with exit code 1

I saw in the flutter doctor that the licenses were not accepted, so I ran flutter doctor --android-licenses and accepted all the licenses successfully. This does not change anything in the build result.

dudozermaks commented 9 months ago

@hatch01 I run flutter doctor myself. It tells me that I have not accepted some licenses too. But for me everything works fine. Might be a stupid question, but have you run nix develop before running flutter build apk? Forgot to mention that in guide (I'll edit it)

hatch01 commented 9 months ago

Of course, I have run nix develop and flutter is not installed system-wide on my NixOS, so I'm sure that I am in the environment.

hatch01 commented 9 months ago

@dudozermaks Here is the repo where I try to make it work if you could try with your system. https://github.com/hatch01/nix-flutter-tests I'm new to nix, but I think that it should not differ between two systems.

dudozermaks commented 9 months ago

To be fair, I don't know where this issue is coming from. Maybe you have another Android SDK installed system-wide? See, in flake.nix we have installed the Android Platform version 33. Could you please send the output of ls /nix/store/ygxvbchm0q2dilfakgvy6srjvkxma26p-androidsdk/libexec/android-sdk/platforms? normally it should look like this: android-28 android-33 (both directories)

hatch01 commented 9 months ago
ll /nix/store/ygxvbchm0q2dilfakgvy6srjvkxma26p-androidsdk/libexec/android-sdk/platforms
lrwxrwxrwx root root 109 B Thu Jan  1 01:00:01 1970  android-28 ⇒ /nix/store/rh4jnhyyhjfx0crkmziy1fl97d7jfbcs-android-sdk-platforms-28/libexec/android-sdk/platforms/android-28
lrwxrwxrwx root root 109 B Thu Jan  1 01:00:01 1970  android-29 ⇒ /nix/store/9kz3pnpf8dzk60v70w8gg68j26q6jv72-android-sdk-platforms-29/libexec/android-sdk/platforms/android-29
lrwxrwxrwx root root 109 B Thu Jan  1 01:00:01 1970  android-30 ⇒ /nix/store/55hzcl7qqyw0qfsgpzbkqa2760s19qks-android-sdk-platforms-30/libexec/android-sdk/platforms/android-30
lrwxrwxrwx root root 109 B Thu Jan  1 01:00:01 1970  android-31 ⇒ /nix/store/jrx532hp58paijacx1pb0cnii5m87spq-android-sdk-platforms-31/libexec/android-sdk/platforms/android-31

Strangely, I have much more

hatch01 commented 9 months ago

If it could help someone, here is a config which accepts all the android sdk licenses for flutter :

pkgs.androidenv.composeAndroidPackages {
          toolsVersion = "26.1.1";
          platformToolsVersion = "33.0.3";
          buildToolsVersions = [ buildToolsVersionForAapt2 ];
          includeEmulator = false;
          emulatorVersion = "34.1.9";
          platformVersions = [ "28" "29" "30" "31" ];
          includeSources = false;
          includeSystemImages = false;
          systemImageTypes = [ "google_apis_playstore" ];
          abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
          cmakeVersions = [ "3.10.2" ];
          includeNDK = true;
          ndkVersions = [ "22.0.7026061" ];
          useGoogleAPIs = false;
          useGoogleTVAddOns = false;
        extraLicenses = [
          "android-googletv-license"
          "android-sdk-arm-dbt-license"
          "android-sdk-license"
          "android-sdk-preview-license"
          "google-gdk-license"
          "intel-android-extra-license"
          "intel-android-sysimage-license"
          "mips-android-sysimage-license"            
       ];
        };
dudozermaks commented 9 months ago

@hatch01 I could not reproduce your error. Steps: gh repo clone https://github.com/hatch01/nix-flutter-tests nix develop flutter build apk try to do them yourself, maybe this will help. but I have no clue why this is happening.

The trouble here is, that for some reason you have no android-33 in your android-sdk folder. Flutter needs it in order to build apk. But in flake.nix specified exactly that version of android platforms...

hatch01 commented 9 months ago

It works, don't know why but thank you x)

hatch01 commented 9 months ago

The solution was to ensure that nothing was in the environment (vscode in my case), and then run nix-collect-garbage -d to cleanup everything.

contrun commented 9 months ago

Unfortunately I can't run the emulator with @hatch01 's devshell on sway. I use this commit https://github.com/hatch01/nix-flutter-tests/commit/266a87c3820fcf357031765c08f3c7af2f6a693c to enable emulator support on x86_64. Here is my script to test emulator running.

export ANDROID_AVD_NAME=device
export ANDROID_USER_HOME=$(mktemp -d $TMPDIR/nix-android-user-home-XXXX)
export ANDROID_AVD_HOME=$ANDROID_USER_HOME/avd
yes "" | avdmanager create avd --force -n $ANDROID_AVD_NAME -k "system-images;android-33;google_apis_playstore;x86_64" -p $ANDROID_AVD_HOME
echo
echo "========================"
echo
env | grep QT_
echo
echo "========================"
echo
emulator -avd device -verbose
echo
echo "========================"
echo
unset $(env | grep '^QT_' | awk -F= '{print $1}')
emulator -avd device -verbose

The emulator first complains that Warning: Could not find the Qt platform plugin "wayland" in "/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64/qt/plugins" ((null):0, (null)) Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. It didn't find the QT plugin.

When I unset QT related environment variables (especially QT_QPA_PLATFORM I think), the emulator directly crashed by SIGABRT. screenshot-2023-12-05-00-37-01

Here is the full output.

[=======================================] 100% Fetch remote repository...
Auto-selecting single ABI x86_64
Do you wish to create a custom hardware profile? [no]
========================

QT_AUTO_SCREEN_SCALE_FACTOR=1
QT_IM_MODULE=fcitx
QT_PLUGIN_PATH=/nix/store/dagifdkbh755wk353xs9fg3sflp2zy0w-fcitx5-with-addons-5.1.5/lib/qt-6/plugins:/home/e/.nix-profile/lib/qt-5.15.11/plugins:/home/e/.nix-profile/lib/qt-6/plugins:/nix/profile/lib/qt-5.15.11/plugins:/nix/profile/lib/qt-6/plugins:/home/e/.local/state/nix/profile/lib/qt-5.15.11/plugins:/home/e/.local/state/nix/profile/lib/qt-6/plugins:/etc/profiles/per-user/e/lib/qt-5.15.11/plugins:/etc/profiles/per-user/e/lib/qt-6/plugins:/nix/var/nix/profiles/default/lib/qt-5.15.11/plugins:/nix/var/nix/profiles/default/lib/qt-6/plugins:/run/current-system/sw/lib/qt-5.15.11/plugins:/run/current-system/sw/lib/qt-6/plugins
QT_QPA_PLATFORM=wayland
QT_QPA_PLATFORMTHEME=gnome
QT_STYLE_OVERRIDE=adwaita
QT_WAYLAND_DISABLE_WINDOWDECORATION=1

========================

INFO    | Android emulator version 34.1.9.0 (build_id 11009885) (CL:N/A)
DEBUG   | Current emulator version 34.1.9 is the same as the required version 34.1.9.
INFO    | Found AVD name 'device'
INFO    | Found AVD target architecture: x86_64
INFO    | argv[0]: '/nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/bin/emulator'; program directory: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator'
INFO    | Found systemPath /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64/
INFO    | emuDirName: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator'
INFO    | try dir /nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator
INFO    | Trying emulator path '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64'
INFO    | Found target-specific 64-bit emulator binary: /nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64
INFO    | Adding library search path: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64'
INFO    | Adding library search path: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64/gles_swiftshader'
INFO    | Adding library search path: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64/libstdc++'
DEBUG   | emulator: Running :/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64
DEBUG   | qemu backend: argv[00] = "/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64"
DEBUG   | qemu backend: argv[01] = "-avd"
DEBUG   | qemu backend: argv[02] = "device"
DEBUG   | qemu backend: argv[03] = "-verbose"
DEBUG   | Concatenated backend parameters:  /nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64 -avd device -verbose
INFO    | Storing crashdata in: , detection is enabled for process: 264632
WARNING | Crash annotation is very large (22899), only 16384 bytes will be recorded, 6515 bytes are lost.
INFO    | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
DEBUG   | autoconfig: -skin 320x640
DEBUG   | autoconfig: -skindir (null)
DEBUG   | autoconfig: -kernel /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//kernel-ranchu
DEBUG   | Target arch = 'x86_64'
DEBUG   | Auto-detect: Kernel image requires new device naming scheme.
DEBUG   | Auto-detect: Kernel does not support YAFFS2 partitions.
DEBUG   | autoconfig: -ramdisk /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//ramdisk.img
DEBUG   | Using initial system image: /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//system.img
DEBUG   | Using initial vendor image: /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//vendor.img
DEBUG   | autoconfig: -initdata /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/userdata.img
DEBUG   | autoconfig: -cache /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/cache.img
INFO    | Increasing RAM size to 2048MB
DEBUG   | VM heap size 0MB is below hardware specified minimum of 512MB,setting it to that value
DEBUG   | System image is read only
DEBUG   | Found 1 DNS servers:
DEBUG   |       127.0.0.53
DEBUG   | found magic skin width=320 height=640 bpp=16
DEBUG   | Starting hostapd main loop.
WARNING | File System is not ext4, disable QuickbootFileBacked feature
DEBUG   | Creating ext4 userdata partition: /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/data
Creating filesystem with parameters:
    Size: 6442450944
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 24576
    Label:
    Blocks: 1572864
    Block groups: 48
    Reserved block group size: 383
Created filesystem with 31/393216 inodes and 52359/1572864 blocks
DEBUG   | convert img from ext4 /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/userdata-qemu.img to qcow2 image /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/userdata-qemu.img.tmp.qcow2  succeeded, using 288 mini seconds
DEBUG   | Creating empty ext4 cache partition: /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/cache.img
Creating filesystem with parameters:
    Size: 69206016
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 4224
    Inode size: 256
    Journal blocks: 1024
    Label:
    Blocks: 16896
    Block groups: 1
    Reserved block group size: 7
Created filesystem with 11/4224 inodes and 1302/16896 blocks
DEBUG   | CPU Acceleration: working
DEBUG   | CPU Acceleration status: KVM (version 12) is installed and usable.
DEBUG   | handleCpuAcceleration: feature check for hvf
DEBUG   | Bluetooth requested by guest
DEBUG   | started modem simulator host server at port: 24697
INFO    | Warning: Could not find the Qt platform plugin "wayland" in "/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64/qt/plugins" ((null):0, (null))
Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.
 ((null):0, (null))
INFO    | Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.
 ((null):0, (null))
[264636:264636:20231205,003453.659821:ERROR elf_dynamic_array_reader.h:64] tag not found
[264636:264636:20231205,003453.660531:ERROR elf_dynamic_array_reader.h:64] tag not found
[264636:264636:20231205,003453.660548:ERROR process_memory_range.cc:75] read out of range
[1]    264632 IOT instruction (core dumped)  emulator -avd device -verbose

========================

INFO    | Android emulator version 34.1.9.0 (build_id 11009885) (CL:N/A)
DEBUG   | Current emulator version 34.1.9 is the same as the required version 34.1.9.
INFO    | Found AVD name 'device'
INFO    | Found AVD target architecture: x86_64
INFO    | argv[0]: '/nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/bin/emulator'; program directory: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator'
INFO    | Found systemPath /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64/
INFO    | emuDirName: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator'
INFO    | try dir /nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator
INFO    | Trying emulator path '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64'
INFO    | Found target-specific 64-bit emulator binary: /nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64
INFO    | Adding library search path: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64'
INFO    | Adding library search path: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64/gles_swiftshader'
INFO    | Adding library search path: '/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64/libstdc++'
DEBUG   | emulator: Running :/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64
DEBUG   | qemu backend: argv[00] = "/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64"
DEBUG   | qemu backend: argv[01] = "-avd"
DEBUG   | qemu backend: argv[02] = "device"
DEBUG   | qemu backend: argv[03] = "-verbose"
DEBUG   | Concatenated backend parameters:  /nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64 -avd device -verbose
INFO    | Storing crashdata in: , detection is enabled for process: 264673
WARNING | Crash annotation is very large (22134), only 16384 bytes will be recorded, 5750 bytes are lost.
INFO    | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
DEBUG   | autoconfig: -skin 320x640
DEBUG   | autoconfig: -skindir (null)
DEBUG   | autoconfig: -kernel /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//kernel-ranchu
DEBUG   | Target arch = 'x86_64'
DEBUG   | Auto-detect: Kernel image requires new device naming scheme.
DEBUG   | Auto-detect: Kernel does not support YAFFS2 partitions.
DEBUG   | autoconfig: -ramdisk /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//ramdisk.img
DEBUG   | Using initial system image: /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//system.img
DEBUG   | Using initial vendor image: /nix/store/a6zm4lvs7a9nbripi3gf7d7xc9pc4a91-androidsdk/libexec/android-sdk/system-images/android-33/google_apis_playstore/x86_64//vendor.img
DEBUG   | autoconfig: -data /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/userdata-qemu.img
DEBUG   | autoconfig: -initdata /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/userdata.img
DEBUG   | autoconfig: -cache /tmp/nix-shell.8bsZtY/nix-android-user-home-EVoe/avd/../avd/cache.img
INFO    | Increasing RAM size to 2048MB
DEBUG   | VM heap size 0MB is below hardware specified minimum of 512MB,setting it to that value
DEBUG   | System image is read only
DEBUG   | Found 1 DNS servers:
DEBUG   |       127.0.0.53
DEBUG   | Starting hostapd main loop.
DEBUG   | found magic skin width=320 height=640 bpp=16
WARNING | File System is not ext4, disable QuickbootFileBacked feature
DEBUG   | CPU Acceleration: working
DEBUG   | CPU Acceleration status: KVM (version 12) is installed and usable.
DEBUG   | handleCpuAcceleration: feature check for hvf
DEBUG   | Bluetooth requested by guest
DEBUG   | started modem simulator host server at port: 34901
INFO    | Warning: Could not find the Qt platform plugin "wayland" in "/nix/store/fb1l88r4gyd2b81m8iaxz4yz8ywnb6al-android-sdk-emulator-34.1.9/libexec/android-sdk/emulator/lib64/qt/plugins" ((null):0, (null))
hatch01 commented 9 months ago

@contrun could I test using your project on my Nixon system?

contrun commented 9 months ago

@hatch01 Do you mean using your flake file without modification? My modification to add x86_64 and includeSystemImages arguments are required because I need these files to run the emulator.

hatch01 commented 9 months ago

@contrun I miss written. My question was, could I get your project to test it myself on my system.

hatch01 commented 9 months ago

https://github.com/maximoffua/flutter.nix/issues/1 see this maybe helpful

contrun commented 9 months ago

@hatch01 Thanks for the pointer. With the help of the code in that link, I am able to start an android emulator, compile the code and run the resulting apk in the emulator. See https://github.com/contrun/nix-flutter-project-template for a sample project.

wexder commented 8 months ago

For anyone struggling to make https://github.com/contrun/nix-flutter-project-template work, make sure you don't have any config set in flutter. Clear it with flutter config --android-sdk= and flutter config --android-studio-dir=

Jonas-Sander commented 5 months ago

If it could help someone, here is a config which accepts all the android sdk licenses for flutter :

pkgs.androidenv.composeAndroidPackages {
          toolsVersion = "26.1.1";
          platformToolsVersion = "33.0.3";
          buildToolsVersions = [ buildToolsVersionForAapt2 ];
          includeEmulator = false;
          emulatorVersion = "34.1.9";
          platformVersions = [ "28" "29" "30" "31" ];
          includeSources = false;
          includeSystemImages = false;
          systemImageTypes = [ "google_apis_playstore" ];
          abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
          cmakeVersions = [ "3.10.2" ];
          includeNDK = true;
          ndkVersions = [ "22.0.7026061" ];
          useGoogleAPIs = false;
          useGoogleTVAddOns = false;
        extraLicenses = [
          "android-googletv-license"
          "android-sdk-arm-dbt-license"
          "android-sdk-license"
          "android-sdk-preview-license"
          "google-gdk-license"
          "intel-android-extra-license"
          "intel-android-sysimage-license"
          "mips-android-sysimage-license"            
       ];
        };

Thanks, this worked! ♥️ Where did you get the license strings from?

hatch01 commented 5 months ago

Trial and error x)