Skip to content
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

flutter android cannot build #260278

Open
Fructokinase opened this issue Oct 10, 2023 · 14 comments
Open

flutter android cannot build #260278

Fructokinase opened this issue Oct 10, 2023 · 14 comments
Labels
0.kind: bug 0.kind: regression Something that worked before working no longer

Comments

@Fructokinase
Copy link

Describe the bug

Android apps create from flutter cannot be built. This issue popped up after the recent update. I think it was working for when flutter was still 3.10.0 on nixpkgs.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install flutter (3.13.4), jdk17, and install android tools into $ANDROID_SDK_ROOT
  2. Create a flutter app: flutter create myapp
  3. Build the android app: cd myapp/android && ./gradlew assembleDebug

This issue has also been reported on stackoverflow

Expected behavior

gradlew assembleDebug should work

Screenshots

Please see the stackoverflow link

Additional context

Specific issues.

  1. Flutter gradle plugin attempts to be built under $FLUTTER_SDK/flutter_tools/gradle. Since $FLUTTER_SDK is read only in nix, this causes the issue mentioned. As far as I know, Gradle includeBuild for plugins have no other way of specifying the buildDir other than directly in the plugin build.gradle file itself. A workaround I found was by patching build.gradle.kts with a line like buildDir = File(System.getenv("FLUTTER_GRADLE_PLUGIN_BUILDDIR"))

  2. FLUTTER_ROOT points to the wrong root? flutter doctor -v points to the unwrapped root. In the android folder for example, local.properties ends up pointing to the unwrapped flutter (I'm assuming unwrapped flutter is not intended to be used directly). I workaround I found was by patching FLUTTER_ROOT in shared.sh to point to the wrapped-linked sdk. Related, I also needed to symlink .git dir from wrapped-link to unwrapped.

Notify maintainers

@babariviere @ericdallo @FlafyDev @hacker102

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here
@RossComputerGuy
Copy link
Member

Try with flutter run or flutter build. I'm pretty sure running gradle directly isn't supported by Flutter.

@Fructokinase
Copy link
Author

@RossComputerGuy flutter run for android apps also fail because it calls gradle build under the hood

@Fructokinase
Copy link
Author

cc @vkryachko

@vkryachko
Copy link

cc @hacker1024 @FlafyDev looks like a regression during the 3.10->3.13 upgrade, mind taking a look? thanks

@Prn-Ice
Copy link

Prn-Ice commented Oct 16, 2023

Ran into this issue today, I tried following the steps to set the GRADLE_OPTS parameter but that didn't work.
Rolling back to Flutter 3.10.5 via this commit 03e12d1 works for me.

I can help with testing & debugging.

@darichey
Copy link
Contributor

I can repro. I also believe the FLUTTER_ROOT issue may be related to Dart-Code/Dart-Code#4800. Downgrading fixed that as well.

@DanTup
Copy link

DanTup commented Oct 19, 2023

Hi 👋

I work on the Dart VS Code extension and think the reason for @darichey's issue could be that the file bin/snapshots/analysis_server.dart.snapshot is missing from the Dart SDK.

In the change linked above was this code:

# Certain prebuilts should be replaced with Nix-built (or at least Nix-patched) equivalents.
rm -r \
$FLUTTER_ROOT/bin/cache/dart-sdk \
$FLUTTER_ROOT/bin/cache/artifacts/engine
'';

Deletion of dart-sdk would certainly cause issues, but it's not clear to me if something is being put back in its place - and if so, whether it includes the snapshots/analysis_server.dart.snapshot file?

@vkryachko
Copy link

@Fructokinase When do you think you can share your fix PR for review?

@Fructokinase
Copy link
Author

Found a working solution for all of the issues above. @DanTup snapshots/analysis_server.dart.snapshot is there but is now under <FLUTTER_ROOT>/bin/cache/dart-sdk/bin/snapshots so ln -sf $out/bin/cache/dart-sdk/bin/snapshots $out/bin/snapshots this should fix it. But perhaps there are other things dart-sdk/bin that I am missing.

I'm not familiar with dart so hoping you can pitch in.

@DanTup
Copy link

DanTup commented Oct 20, 2023

snapshots/analysis_server.dart.snapshot is there but is now under <FLUTTER_ROOT>/bin/cache/dart-sdk/bin/snapshots

I'm not sure I understand the difference - that last path is where I expected it to be (the Dart SDK is at bin/cache/dart-sdk and the snapshot is at bin/snapshots/... in the Dart SDK). It does not need to be in the bin folder of the Flutter SDK.

@hacker1024 hacker1024 added the 0.kind: regression Something that worked before working no longer label Oct 21, 2023
@PaulGrandperrin
Copy link
Contributor

I basically know nothing about flutter and android dev but I wanted to start a project.
I have the same error doing flutter create.. flutter build apk.

After investigating, I'm pretty sure the issue comes from this PR: flutter/flutter#123511

I don't really know how to move forward with that, but I'm hoping that might save some investigation time.

@PaulGrandperrin
Copy link
Contributor

I'm still unable to find any workaround to use flutter on either 23.05 or unstable. Is there any?

Is going back to 03e12d1 the only solution yet?

@heyzec
Copy link
Contributor

heyzec commented Dec 15, 2023

The solution in https://discourse.nixos.org/t/problem-building-flutter-app-for-android/35593/2 proposed by user chito worked for me.

@dudozermaks
Copy link

Hi there! I created issue for documentation on this problem, and created a (mostly) working flake for building android projects. Issue: #267263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 0.kind: regression Something that worked before working no longer
Projects
None yet
Development

No branches or pull requests

10 participants