├── .gitignore ├── config-common.sh ├── bin └── flutterfx ├── flutter-gallery-on-fuchsia.png ├── .gitmodules ├── LICENSE ├── flutterfx └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /.pub-cache -------------------------------------------------------------------------------- /config-common.sh: -------------------------------------------------------------------------------- 1 | USE_MODIFIED_FLUTTER=1 2 | -------------------------------------------------------------------------------- /bin/flutterfx: -------------------------------------------------------------------------------- 1 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 2 | "$DIR/../flutterfx" $@ 3 | -------------------------------------------------------------------------------- /flutter-gallery-on-fuchsia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaellee8/flutter_fuchsia_toolchain/HEAD/flutter-gallery-on-fuchsia.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "fuchsia-cpp-gn-sdk"] 2 | path = fuchsia-cpp-gn-sdk 3 | url = https://fuchsia.googlesource.com/samples 4 | branch = main 5 | fetchRecurseSubmodules = true 6 | shallow = true 7 | [submodule "flutter"] 8 | path = flutter 9 | url = https://github.com/flutter/flutter 10 | branch = master 11 | fetchRecurseSubmodules = true 12 | shallow = true 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2020, michaellee8 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /flutterfx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | source "$DIR/config-common.sh" 6 | 7 | if [[ "$1" == "bootstrap" ]];then 8 | cd $DIR 9 | git submodule init 10 | 11 | cd fuchsia-cpp-gn-sdk && ./scripts/setup-and-test.sh && cd ../ 12 | 13 | ./flutter/bin/flutter precache --fuchsia --all-platforms 14 | 15 | exit 16 | fi 17 | 18 | if [[ "$1" == "dir" ]];then 19 | echo $DIR 20 | exit 21 | fi 22 | 23 | if [[ "$1" == "readme" ]];then 24 | cd $DIR 25 | less README.md 26 | exit 27 | fi 28 | 29 | if [[ "$1" == "update" ]];then 30 | cd $DIR 31 | git submodule update --init --recursive 32 | git pull 33 | exit 34 | fi 35 | 36 | if [[ "$1" == "fuchsia" ]];then 37 | "$DIR/fuchsia-cpp-gn-sdk/third_party/fuchsia-sdk/bin/$2.sh" "${@:3}" 38 | exit 39 | fi 40 | 41 | if [[ "$1" == "ffx" ]]; then 42 | "$DIR/fuchsia-cpp-gn-sdk/third_party/fuchsia-sdk/tools/x64/ffx" "${@:2}" 43 | exit 44 | fi 45 | 46 | if [[ "$1" == "flutter" ]];then 47 | if [[ -n "$USE_MODIFIED_FLUTTER" ]]; then 48 | PUB_CACHE="$DIR/.pub-cache" "$DIR/flutter/bin/cache/dart-sdk/bin/dart" \ 49 | "$DIR/flutter/packages/flutter_tools/bin/flutter_tools.dart" \ 50 | "${@:2}" 51 | else 52 | PUB_CACHE="$DIR/.pub-cache" "$DIR/flutter/bin/flutter" \ 53 | "${@:2}" 54 | fi 55 | exit 56 | fi 57 | 58 | 59 | 60 | show_help(){ 61 | cat << EOF 62 | usage: flutterfx 63 | 64 | bootstrap: init submodule and download required artifacts 65 | update: update this repo and submodules 66 | fuchsia : run in the fuchsia sdk 67 | flutter : run in the flutter sdk 68 | readme: show the readme file 69 | help: display this message 70 | EOF 71 | } 72 | 73 | if [[ "$1" == "help" ]];then 74 | show_help 75 | exit 76 | fi 77 | 78 | show_help 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter SDK setup for developing with Fuchsia SDK 2 | 3 | This project aims to provide guidance to developing Flutter applications for 4 | Fuchsia using the Fuchsia GN C++ SDK. It does not require downloading and 5 | building Fuchsia locally, which is enromusly big. 6 | 7 | Disclaimer: This project have no relation with Google. This is unofficial. 8 | Use this at your own risk! 9 | 10 | Those scripts are tested to work in Ubuntu 18.04 LTS. 11 | 12 | ## Required patches 13 | 14 | Before https://github.com/flutter/flutter/pull/84759 is merged, one will need 15 | the modification in https://github.com/michaellee8/flutter/tree/fix/fuchsia-pm-serve 16 | to use `flutter run` properly. 17 | 18 | ## Features 19 | 20 | - Running Fuchsia in emulator/on device without cloning and compiling the whole source tree using Google's Fuchsia SDK. 21 | - Can run Flutter apps with hot-reload enabled, and build a release package and then push it into Fuchsia as well. 22 | - Wrapped into one single command flutterfx to call all these tools. 23 | 24 | ## Video tutorial 25 | https://youtu.be/gxV8EN9vzbc 26 | - Remember to do `export FUCHSIA_SSH_CONFIG=$HOME/.fuchsia/sshconfig` before running flutter run in any shell, I didn't do that in the video since I have it in my .bashrc . 27 | - Also I forgot to mention that any new Flutter project will require a cmx file to be able to run/bulild on Fuchsia, an example can be found at https://github.com/michaellee8/flutter_gallery/blob/master/fuchsia/meta/flutter_gallery.cmx 28 | - Manually aplying the patch should be no longer required now since my PR has already been accepted. 29 | 30 | ## Expected Result 31 | 32 | ![Flutter Gallery on Fuchsia!](flutter-gallery-on-fuchsia.png) 33 | 34 | ## Command usage 35 | ``` 36 | usage: flutterfx 37 | 38 | bootstrap: init submodule and download required artifacts 39 | update: update this repo and submodules 40 | fuchsia : run in the fuchsia sdk 41 | flutter : run in the flutter sdk 42 | readme: show the readme file 43 | help: display this message 44 | ``` 45 | 46 | ## Prerequisites 47 | The below commands reflect the libraries and utilities you have to install before you can get started. 48 | However these command will probably differ depending on your OS and distro. 49 | 50 | ```sh 51 | sudo apt-get install curl unzip python2 \ 52 | libglu1-mesa bash curl git unzip xz-utils zip \ 53 | libvulkan1 mesa-vulkan-drivers 54 | ``` 55 | 56 | ## Setting up for flutter run (working now) 57 | It is verified that hot reload iw working as well. Use it by pressing r 58 | in the terminal after launching the flutter app with flutter run. 59 | ```sh 60 | git clone http://github.com/michaellee8/flutter_fuchsia_toolchain --recurse-submodules --recursive --depth 1 --shallow-submodule --remote-submodules 61 | # Assumes you have added ./bin to your path, if you haven't, use ./bin/flutterfx instead of flutterfx 62 | # You need to apply my patch at https://github.com/flutter/flutter/pull/55664/files before it is merged 63 | flutterfx bootstrap 64 | flutterfx flutter config --enable-fuchsia 65 | flutterfx bootstrap 66 | sudo ip tuntap add dev qemu mode tap user $USER && sudo ip link set qemu up 67 | flutterfx fuchsia femu -N --image qemu-x64 68 | flutterfx fuchsia fserve --image qemu-x64 69 | cd flutter_gallery # See Note 4 70 | export FUCHSIA_SSH_CONFIG=$HOME/.fuchsia/sshconfig # See Note 2 71 | flutterfx flutter run --verbose -d 72 | ``` 73 | 74 | ## So how do I actually run my Flutter app in Fuchsia (using flutter build on workstation flavor here) 75 | 76 | Okay, I know why you are here. There are a lot of quirks here. ~~`flutter run` after applying my 77 | patch still breaks because of some `rust tuf` I/O error~~ (working now) (you can see it with log_listener). Also 78 | for some reason it is not possible to launch a package via tiles_ctl or sessionctl on the emulator 79 | and the ermine (the desktop environment you see in the workstation flavour) will not load any 80 | package name that is not present in the original package repo. So my hack is to force updating 81 | the `flutter_gallery` package and then launch it from ermine. You can do further work by changing my 82 | `flutter_gallery` checkout. 83 | 84 | The command below assumes that you start from scratch, on a Linux environment (I use Ubuntu 18.04 LTS). 85 | You are advised to follow it strictly. You may want to mess around yourself later through but this 86 | is the only way that is verified to work. Prepare a great internet connection or wait for hours. 87 | 88 | Note that (term1) (term2) (term3) ... means different terminal. You will need a few of them. 89 | 90 | ```sh 91 | cd ~ 92 | git clone https://github.com/michaellee8/flutter_fuchsia_toolchain.git --recursive 93 | git clone https://github.com/michaellee8/flutter_gallery.git 94 | # install ~/flutter_fuchsia_toolchain/bin to your path 95 | # Before my PR being merged, you will need to apply the patch in 96 | # https://github.com/flutter/flutter/pull/55715 to ./flutter 97 | flutterfx bootstrap 98 | sudo ip tuntap add dev qemu mode tap user $USER && sudo ip link set qemu up 99 | (term1) cd flutter_gallery 100 | (term1) flutterfx flutter pub get 101 | (term1) flutterfx flutter build fuchsia --release --runner-source fuchsia.com \ 102 | --tree-shake-icons --verbose --target-platform fuchsia-x64 103 | (term2) flutterfx fuchsia femu -N --image workstation.qemu-x64-release 104 | (term3) flutterfx fuchsia fserve --image workstation.qemu-x64-release 105 | (term1) flutterfx fuchsia fpublish ./build/fuchsia/pkg/flutter_gallery-0.far 106 | (term1) cd "$(flutterfx dir)/flutter/bin/cache/artifacts/flutter_runner/flutter/x64/release" && \ 107 | flutterfx fuchsia fpublish aot/flutter_aot_product_runner-0.far \ 108 | aot/dart_aot_product_runner-0.far jit/flutter_jit_product_runner-0.far \ 109 | aot/dart_jit_product_runner-0.far && cd ~/flutter_gallery 110 | (term4) flutterfx fuchsia fssh log_listener 111 | # in the ermine ui shell, type flutter_gallery and then press enter to launch it 112 | # if you face Error while initializing the Dart VM: Wrong full snapshot version, expected 113 | # you will need to do 114 | # flutterfx flutter clean 115 | # cd ~/flutter_fuchsia_toolchain/flutter/bin 116 | # rm -rf ./cache 117 | ``` 118 | 119 | 120 | ## Some notes 121 | 1. You may want to add `./flutter_fuchsia_toolchain/bin` to your PATH. 122 | 2. You will need `export FUCHSIA_SSH_CONFIG=$HOME/.fuchsia/sshconfig` to setup flutter's connection to the device. 123 | 3. Use `--verbose` for debugging. 124 | 4. You may want to look at my flutter gallery fork at https://github.com/michaellee8/flutter_gallery to look for 125 | fuchsia specific config. 126 | 5. A link on the full snapshot error (chinese) https://juejin.im/post/5d0dfd6f518825329840196d 127 | 6. Interestingly, `flutter run` only works on qemu-x64 image. Maybe it is because workstation does not have tiles. 128 | 7. If you don't to modify your path, you may also `cd` into repo root and do `alias flutterfx="$(pwd)/bin/flutterfx"`. 129 | 8. If you use shallow clone and ran into some flutter veriosn issues, either 130 | follow the steps in https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#flutter-installation-corrupted 131 | and then run `git pull --unshallow` on the flutter git repo 132 | or just delete the version constriant in your flutter app's pubspec.yaml, the 133 | former one should be considered as the more approiate solution but require 134 | more download size. 135 | 9. Add `--software-gpu` to the `femu` command if you hit any Vulkan or Dart 136 | Observatory issues. It is the mitigation for using Intel GPU on Linux. 137 | 138 | ## Known issues 139 | 1. Somehow the guest will not launch the installed packages currently, will be 140 | investigated. Currently a patch at https://github.com/flutter/flutter/pull/55664 adresses the ipv6 141 | issue, but some other bugs are being investigated. 142 | 143 | ## Emulator flavours 144 | You should look at the values listed in here (or newer directories): 145 | https://console.cloud.google.com/storage/browser/fuchsia/development/5.20210616.2.1/images/?authuser=0 146 | 147 | - qemu-arm64 148 | - qemu-x64 149 | - workstation.qemu-x64-release (you probably want to use this default) 150 | 151 | ## Where are the files? 152 | - This folder 153 | - ~/.fuchsia 154 | 155 | ## Configuration 156 | `config-common.sh` 157 | - `USE_MODIFIED_FLUTTER`: If this is not set to empty, flutterfx will use dart toolchain to run all flutter commands 158 | which runs flutter from source. If it is empty, flutterfx will use the flutter command directly, which uses the faster snapshot 159 | method instead. It should be set to non-empty if you want to run a modified flutter toolchain. 160 | 161 | ## Quick commands 162 | ```sh 163 | git clone https://github.com/michaellee8/flutter_fuchsia_toolchain.git --recursive 164 | sudo ip tuntap add dev qemu mode tap user $USER && sudo ip link set qemu up 165 | ifconfig qemu | grep inet6 166 | flutterfx fuchsia femu -N --image workstation.qemu-x64-release 167 | flutterfx fuchsia fserve --image workstation.qemu-x64-release 168 | flutterfx fuchsia fpublish ~/gallery/build/fuchsia/pkg/gallery-0.far # if you are playing with flutter gallery 169 | flutterfx flutter build fuchsia --release --verbose --runner-source fuchsia.com --tree-shake-icons 170 | flutterfx flutter run -d 171 | flutterfx fuchsia fssh log_listener --clock Local 172 | 173 | # if fssh somehow won't work, use this instead 174 | ssh -F /home/michaellee8/.fuchsia/sshconfig fe80::89ff:4714:d9a3:586c%qemu 175 | ``` 176 | 177 | ## To uninstall/reinstall 178 | **Make sure you know what you are doing before typing these commands!** 179 | ```sh 180 | rm -rf $(flutterfx dir) # This command will get you the installation location of the toolchain 181 | # and delete it completely 182 | rm -rf ~/flutter_gallery # If you cloned the flutter gallery there 183 | rm -rf ~/.fuchsia # Default location of fuchsis sdk's image and package cache 184 | ``` 185 | 186 | ## IDE Setup 187 | You just need to set the Flutter SDK location of your IDE to `$(flutterfx dir)/flutter`, which should be `~/flutter_fuchsia_toolchain/flutter` if you followed the suggestions above. 188 | --------------------------------------------------------------------------------