Flutter App Development in Fedora Silverblue


#1

Hi,
I recently switched to Fedora Silverblue. I configured everything and my Desktop is working great so far :slight_smile:.

I now have to develop a Flutter app for a study project.

alexl lists here three possibilities to accomplish it.

The first option is not possible due to needed changes in Android Studio or Visual Studio Code. Probably through a extension vscode could be enhanced to support containerized workflow for mobile app development.

The second option would require flatpak sdk extensions for Android, Flutter and Java.
Right now there aren’t flatpak sdk extensions available for Android and Flutter. As I have not enough knowledge to build suchs flatpaks and it would require me to invest much time which I don’t have right now, this isn’t an option. Though the Java sdk extension should be useful.

I installed org.freedesktop.Sdk.Extension.openjdk11/x86_64/18.08 from flathub. So from the terminal in vscode I can navigate to /usr/lib/openjdk11/. There is a script to enable it:

enable.sh:

#!/bin/sh
export JAVA_HOME=/usr/lib/sdk/openjdk11/jvm/openjdk-11
export PATH=$PATH:/usr/lib/sdk/openjdk11/bin

But this is not working.

The third option is command invocation through flatpak-spawn --host. This seems for me the easiest approach. I downloaded the flutter sdk, set up my PATH variable and voila flatpak-spawn --host flutter doctor is detecting the flutter binary.

bash-4.4$ flatpak-spawn --host flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Linux, locale de_DE.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    ✗ No Java Development Kit (JDK) found; You must have the environment variable JAVA_HOME set and the java
      binary in your PATH. You can download the JDK from
      https://www.oracle.com/technetwork/java/javase/downloads/.
[!] Android Studio (not installed)
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

Because this trial and error approach is taking quite some time I thought maybe someone else has already setup his flutter development environment.

So can anyone help me to set up a flutter development environment with Android Studio or Visual Studio Code?

Thanks in Advance :grinning:


#2

I have a working but terribly ugly Flutter Flatpak manifest I can upload later today. You need Android Studio installed + have already downloaded the SDK through Studio for it to work, and it’s absolutely terrible from a cleanliness standpoint, but hey, it works… ¯\_(ツ)_/¯


#3

I’ve experimenting with an approach for IDE’s under Silverblue. The basic idea is that fedora-toolbox exports a magic filesystem $HOME/.local/share/fedora-toobox/env/_default/exe where running binaries actually runs them inside the toolbox. (Executing a binary actually executes a shell script that use flatpak-spawn or podman exec.) Then you can point PATH, JAVA_HOME, etc, to that directory. I’ve tested that the basics work for Java inside of vscode with this approach.

It’s highly experimental - even if you can get it working, it’s probably going to take hours of fiddling, but if you want to try it out, basic instructions would look like:

Inside your fedora-toolbox environment:

mkdir build
cd build
meson ..
ninja

Outside your toolbox:

cd <path_to_checkout>/build
./toolboxd &
  • check that $HOME/.local/share/fedora-toolbox/env/_default/exe/usr/bin/ps works (should show only a few processes)
  • Change overrides for com.visualstudio.code.oss or com.visualstudio.code (depending on what you are using)
flatpak override <ID> \
      --talk=org.freedesktop.Flatpak \
      --env=PATH=/app/bin:/usr/bin:/app/bin:/usr/bin:$HOME/.local/share/fedora-toolbox/env/_default/exe/usr/bin \
      --env=ENV_ROOT=$HOME/.local/share/fedora-toolbox/env

In vscode:

  • In user settings, set java.home to <your $HOME>/.local/share/fedora-toolbox/env/_default_/exe/usr/lib/jvm/java-11-openjdk-11.0.1.13-4.fc29.x86_64/" (or whatever JAVA_HOME you need)
  • Optional: set: terminal.integrated.shell.linux to <your home>/.local/share/fedora-toolbox/env/_default/exe/usr/bin/bash (this is convenient when you are programming, but not so good for debugging what is going wrong with the setup.)

If you can get that working, congratulations! The eventual idea:

  • Make this a standard part of fedora-toolbox, make launching toolboxd automatic
  • Get support for this integrated into IDE’s or upstream at least the Flatpak packaged versions
  • Support multiple toolboxes, allow someone to provide a Dockerfile/image for “Flutter development” toolbox

So you just run ‘fedora-toolbox create --type=Flutter’, then in vscode workspace settings, select the Flutter toolbox. That’s the dream anyways :slight_smile:


#4

That would be awesome :slight_smile:.

I guess you mean the Android Studio zip file from Google.

Because I installed Android Studio from flathub and let the wizard download the usual stuff (Android SDK + Emulator). But it’s not possible to build an apk within studio with this version.

10 mins later …

Wait. I’m so silly :blush:. If you just use the Android Studio zip file distributed by Google everything is working fine. I was so excited about flatpak that I didn’t considered that :sweat_smile:.

Nevertheless I’m still interested in a flatpak solution :sunglasses:.


#5

Thanks for your thorough guide :slight_smile:.

Will try your approach when I have more time :timer_clock:.


#6

Okay, I had to update it for Flutter 1.0, but here it is: https://github.com/kirbyfan64/flutter-flatpak

Basically, you’d just make sure the Android Studio Flatpak is installed, then do:

flatpak-builder --force-clean --install _build io.flutter.Flutter.yaml

then you can flatpak run io.flutter.Flutter.


#7

Hello @smartens,
I have been struggling for the most part with using IDE’s in flatpak form. That is until recently anyway. I do some java development in my day to day life. I like to use IntelliJ’s IDEA CE ide, but when I started out using Silverblue around F28, there really were no visible options as a flatpak, and fedora-toolbox hadn’t come along, so I first went to what I know, the rpm repo’s and tried rpm-ostree layering. This is a mixed result that deviates greatly from both the intent of the OS core ideas, with respect to the isolation of applications from one another and the host, plus it doesn’t actually facilitate workflow on your PC as well as it would have been if the PC was just a F29 workstation setup as per normal, let’s call it legacy. So flatpaks keep coming and one day Netbeans appears and it is working fine for openjdk 10, but not 11 or 9 or 8 even, and I still really wanted IDEA. Within days, there was an IDEA flatpak, and I installed it excitedly, only to crash to disappointment again as I was faced with not being able to use my layered JDK11! I decided to “help” the people who flatpak’d IDEA and modified their original manifest and built a fully working flatpak with openjdk10 and 11 and 9 as sdk extensions, man was I stoked now! I committed it and issued a PR, then was duly informed my changes weren’t necessary. All I had to do was install the extensions for openjdk 9, 10 and 11 and IDEA and NB both can see them. I can build java apps in both and compile them then run them in the ide or in my fedora-toolbox container. Openjdk 9 extension is not working it seems.