-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation: Flutter Flake #267263
Comments
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! |
@johynpapin Can you please share your |
Is the "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"
}
}, |
After some modifying of |
Alright, solution to this problem is:
flake.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
build.gradle (EXAMPLE ONLY, you should modify it yourself!!!)Before
After
|
@dudozermaks I created an empty dir, copied you flake.nix and flake.lock.
I saw in the flutter doctor that the licenses were not accepted, so I ran |
@hatch01 I run |
Of course, I have run |
@dudozermaks Here is the repo where I try to make it work if you could try with your system. |
To be fair, I don't know where this issue is coming from. Maybe you have another Android SDK installed system-wide? See, in |
Strangely, I have much more |
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"
];
}; |
@hatch01 I could not reproduce your error. 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 |
It works, don't know why but thank you x) |
The solution was to ensure that nothing was in the environment (vscode in my case), and then run |
Unfortunately I can't run the emulator with @hatch01 's devshell on sway. I use this commit hatch01/flutter-nix-template@266a87c 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 When I unset Here is the full output.
|
@contrun could I test using your project on my Nixon system? |
@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. |
@contrun I miss written. My question was, could I get your project to test it myself on my system. |
maximoffua/flutter.nix#1 see this maybe helpful |
@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. |
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 |
Thanks, this worked! |
Trial and error x) |
Problem
Can't run flake from documentation
How to reproduce:
flake.nix
with content as follows.nix develop
.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
to:
this flake builds, then running
flutter create somename
cd somename
flutter build apk
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 withflake.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
The text was updated successfully, but these errors were encountered: