-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
Unable to build flutter app with flutter 3.19 new Gradle structure #289936
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/problem-building-flutter-app-for-android/35593/3 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/flutter-development-in-nixos/39181/5 |
Ah sorry I didn't know about this issue("notify maintainers" is empty) I'll try to figure out how it works and hopefully find a fix.. |
@jtojnar @hedning @amaxine @bobby285271 @dasj19 (Not sure who to @ exactly, sorry if I @'d the wrong people!!) This issue is also in NixOS 23.11 Stable. Should the flutter package version be reverted to an older one until this is fixed? |
@FlafyDev Did you find anything to fix the problem? |
Any updates on this? |
I managed to build with flutter 3.19.0 the default flutter project. And also, since gradle has this line in
it tries to create a .gradle directory in Flutter's sdk, which on NixOS would be readonly. EDIT 1: just an idea without much knowledge about gradle, but maybe we can build that .gradle directory in the nix package so that it doesn't even need to create anything on when building the project at runtime? EDIT 2: edit 1 doesn't seem to be possible, it tries to write lock files in |
After a lot of trial and error with gradle, I managed to find a solution. diff --git a/pkgs/development/compilers/flutter/flutter.nix b/pkgs/development/compilers/flutter/flutter.nix
index 03c2968f4ab9..627a40dcb1db 100644
--- a/pkgs/development/compilers/flutter/flutter.nix
+++ b/pkgs/development/compilers/flutter/flutter.nix
@@ -82,6 +82,9 @@ let
"dartSdkVersion": "${dart.version}"
}
EOF
+
+ # Suppress error now that `.gradle` location changed from our patch.
+ mkdir -p "$out/packages/flutter_tools/gradle/.gradle"
'';
installPhase = ''
diff --git a/pkgs/development/compilers/flutter/versions/3_19/patches/gradle-tools-wrapper.patch b/pkgs/development/compilers/flutter/versions/3_19/patches/gradle-tools-wrapper.patch
new file mode 100644
index 000000000000..e3943fb394df
--- /dev/null
+++ b/pkgs/development/compilers/flutter/versions/3_19/patches/gradle-tools-wrapper.patch
@@ -0,0 +1,28 @@
+Adds an intermediate gradle build to change flutter_tools' gradle project from
+creating `build` and `.gradle` directories in the nix store.
+This patch moves them to "$HOME/.cache/flutter/nix-flutter-tools-gradle/$engineShortRev"
+diff --git a/packages/flutter_tools/gradle/settings.gradle b/packages/flutter_tools/gradle/settings.gradle
+new file mode 100644
+index 0000000000..b2485c94b4
+--- /dev/null
++++ b/packages/flutter_tools/gradle/settings.gradle
+@@ -0,0 +1,19 @@
++rootProject.buildFileName = "/dev/null"
++
++def engineShortRev = (new File("$settingsDir/../../../bin/internal/engine.version")).text.take(10)
++def dir = new File("$System.env.HOME/.cache/flutter/nix-flutter-tools-gradle/$engineShortRev")
++dir.mkdirs()
++def file = new File(dir, "settings.gradle")
++
++file.text = """
++rootProject.projectDir = new File("$settingsDir")
++apply from: new File("$settingsDir/settings.gradle.kts")
++
++gradle.allprojects { project ->
++ project.beforeEvaluate {
++ project.layout.buildDirectory = new File("$dir/build")
++ }
++}
++"""
++
++includeBuild(dir) |
Edit: I was using a different flake. The one you provided (after removing melos) works! I am impressed. |
This is quite amazing. When can I expect to see this in |
This works perfectly using my personal flake! |
Good to hear it works! I'll make a PR..
After I make a PR and it gets merged it will be on master. Probably a few days after merging it will be on unstable |
Thank you @FlafyDev. I am interested in contributing to the |
Creating tests would definitely be helpful! There is an issue about it #262507. |
Hi, with a recent nixpkgs update, the exact same issue came back
|
Is it because of 3.24? Can you check if you're getting the error on flutter 3.22 or 3.24 (or both) |
@FlafyDev
Settings file '/home//android/settings.gradle' line: 25 contains
on flutter 3.22 |
initial commit after which the error started is I don't think this is any important information, but it confused me that the day before (2024-08-27) most commits were with version 3.22 and only on this commit |
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0'] Failed to create directory .. /gradle/.gradle/buildOutputCleanup see NixOS/nixpkgs#289936
Will be fixed with #341133 |
I am still getting this error on flutter v3.24.1. I can see the redirect |
Is there a local cache, like .direnv or .devenv etc, that wll causes the flutter in the working folder to be not fresh
|
There is a .direnv cache, but I've removed it, both by doing |
Hm, what is interesting is that if I look in the |
So I'm still dealing with this issue, and one thing I've noticed is that it only happens in Android Studio when gradle tries to sync. Running flutter from the command line works fine, which is interesting. |
Was there a fix for this? |
On my, side, I was now able to build with the flutter 3.19 . |
Gradle sync still fails with the same issue on Flutter 3.27.1 |
|
I am having the same problem as well with flutter 3.27 and performing gradle sync in android studio. @hatch01 would you be willing to reopen this issue? |
Describe the bug
Now building the apk of a brand new created, flutter apps try to write in read only nix folders.
Steps To Reproduce
Steps to reproduce the behavior:
flutter create {name of project}
flutter build apk
Expected behavior
The build failed because flutter does not have the right to write in some folders
Additional context
There were a previous similar issue fixable by modifying the build.gradle but because it changed, the previous modification from here is not applicable. (https://discourse.nixos.org/t/problem-building-flutter-app-for-android/35593/2)
Notify maintainers
Metadata
Add a 👍 reaction to issues you find important.
The text was updated successfully, but these errors were encountered: