5

I'm trying to build a flutter app for raspberry.

The raspberry has 2022-09-22-raspios-bullseye-arm64.img.xz image as Operation System. The uname is "Linux raspberrypi 5.15.61-v8+ #1579 SMP PREEMPT Fri Aug 26 11:16:44 BST 2022 aarch64 GNU/Linux"

These are my steps:

pi@raspberrypi:~ $ flutter create my_app
Building flutter tool...
Waiting for another flutter command to release the startup lock...
Creating project my_app...
Running "flutter pub get" in my_app...
Resolving dependencies in my_app... (3.0s)
+ async 2.10.0
+ boolean_selector 2.1.1
+ characters 1.2.1
+ clock 1.1.1
+ collection 1.17.0
+ cupertino_icons 1.0.5
+ fake_async 1.3.1
+ flutter 0.0.0 from sdk flutter
+ flutter_lints 2.0.1
+ flutter_test 0.0.0 from sdk flutter
+ js 0.6.6
+ lints 2.0.1
+ matcher 0.12.14
+ material_color_utilities 0.2.0
+ meta 1.8.0
+ path 1.8.3
+ sky_engine 0.0.99 from sdk flutter
+ source_span 1.9.1
+ stack_trace 1.11.0
+ stream_channel 2.1.1
+ string_scanner 1.2.0
+ term_glyph 1.2.1
+ test_api 0.4.17
+ vector_math 2.1.4
Changed 24 dependencies in my_app!
Wrote 129 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

But when I try to run the app I get this error

pi@raspberrypi:~/my_app $ flutter run
Launching lib/main.dart on Linux in debug mode...
ERROR: Compilation to SkSL failed.
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag: warning: (version, profile) forced to be (460, core), while in source code it is (320, es)
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag:9: error: '#include' : Included file not found. for header name: flutter/runtime_effect.glsl
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag:93: error: 'FlutterFragCoord' : no matching overloaded function found
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag:93: error: '=' :  cannot convert from ' const float' to ' temp 2-component vector of float'
ERROR: Target debug_bundle_linux-arm64_assets failed: ShaderCompilerException: Shader compilation of "/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag" to "/home/pi/my_app/build/flutter_assets/shaders/ink_sparkle.frag" failed with exit code 1.
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag: warning: (version, profile) forced to be (460, core), while in source code it is (320, es)
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag:9: error: '#include' : Included file not found. for header name: flutter/runtime_effect.glsl
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag:93: error: 'FlutterFragCoord' : no matching overloaded function found
/home/pi/snap/flutter/common/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag:93: error: '=' :  cannot convert from ' const float' to ' temp 2-component vector of float'
Building Linux application...                                           
Exception: Build process failed

This is my flutter doctor

pi@raspberrypi:~/my_app $ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.7.0-13.0.pre.31, on Debian GNU/Linux 11 (bullseye) 5.15.61-v8+, locale en_GB.UTF-8)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      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.
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] Connected device (1 available)
[✓] HTTP Host Availability

! Doctor found issues in 3 categories.
Jaime Roman
  • 749
  • 1
  • 11
  • 26
  • I have the same problem and I haven't found any solution yet, maybe the only option for now is to run it on the browser using `flutter run -d chrome` until a solution is found. Also, don't forget to set chromium as the chrome executable using `export CHROME_EXECUTABLE=chromium-browser` before running it on the browser. – amir-msh Jan 01 '23 at 17:46
  • 2
    May be a solution, but I really prefer a linux desktop app, thank you very much – Jaime Roman Jan 01 '23 at 23:24
  • @AmirMohammadMashayekhi, I was really looking for is to do a cross-build and when it gave an error I tried to do a native building that didn't turn out to be satisfactory either. I leave you the link of the cross build error in case you can give me a hand. Thank you https://stackoverflow.com/questions/74978074/how-to-cross-build-a-flutter-app-from-linux-x64-host-to-linux-arm64 – Jaime Roman Jan 01 '23 at 23:53
  • Per this comment: https://github.com/flutter/flutter/issues/60678#issuecomment-1021631389 it seems you need to install the Flutter SDK by cloning the Flutter git repo, is that how you installed Flutter on your RPI? – Maks Jan 04 '23 at 01:08
  • 1
    @Maks, Thank you very much for your answer, sorry for taking so long to answer you, I was reviewing the documentation once again. Finally with your help I did it, I am preparing the answer to serve the community. Again thank you very much. – Jaime Roman Jan 05 '23 at 13:50
  • @JaimeRoman no worries at all, not sure if you mean you found a workaround to get cross compiling working? but if you did that would be fantastic! if you could share it with the community either here or on the Github issue that would be great. – Maks Jan 05 '23 at 23:35
  • 1
    @Maks, I will surely share it, I really have little time but I will surely share it. I was not able to cross-compile, everything is very confusing to me, some say yes, however, in the thread itself they say that it is blocked and they link to the issue. What I was able to achieve was that `flutter build linux` would work from a raspberry and for me it is enough at this point because from the ci/cd I could do the build. Thanks for everything – Jaime Roman Jan 06 '23 at 03:35
  • @JaimeRoman Sorry for the late reply, I'm glad you finally found the solution – amir-msh Jan 08 '23 at 14:12

1 Answers1

3

Here is the solution, after all it was quite simple. The error above was given because I was installing flutter on the raspberry via snap, when I tried cloning the repository it worked fine.

Here he left the steps:

#install prerequisites
sudo apt update && sudo apt install -y cmake ninja-build clang libgtk-3-dev git curl unzip

#to simplify more I have left it in the $HOME
cd $HOME
git clone https://github.com/flutter/flutter.git -b stable
sudo ln -s /home/pi/flutter/bin/flutter /usr/bin/
flutter doctor
flutter create my_app
cd my_app
flutter build linux

For docker lovers I have created a very basic image, here it is, docker pull jaimemanuelroman/flutter_ubuntu:bionic. To work with it, you must map the folder where you want to create the project to /var/app.

To create a project from scratch would be:

cd $HOME
mkdir my_app
docker run --rm -v /home/pi/my_app/:/var/app jaimemanuelroman/flutter_ubuntu:bionic bash -c "flutter create . && flutter build linux"

And when we go to $HOME/my_app/build/linux/arm64/release/bundle/ we will have our app compiled.

NOTE: I was only able to create the image to run on arm64/v8 pq on armv7l, it gave an error. I could also build it for amd64 if someone needs it.

Jaime Roman
  • 749
  • 1
  • 11
  • 26