Thanks for the reply. Also a big thanks to the ubuntu-flutter-community channel on discord. The purpose is to customize the parameters of flutter build linux.
This problem has been solved, the solution is as follows.
1ăUpdate snapcraft.yaml
parts:
app_name:
source: .
plugin: flutter
flutter-target: lib/main.dart # The main entry-point file of the application
override-build: |
cp -r build/linux/*/release/bundle/* $CRAFT_PART_INSTALL/
2ăI run flutter build linux --release --dart-define-from-file=.env --verbose --target lib/main.dart in the root directory of the flutter project, and then run snapcraft --verbose --output app_name.snap
This needs a little bit update, if you just run override-build without using the flutter build commands, the app will not build, itâll just execute the cp command, which in turn would find empty files.
I understand what you mean is that it is best to execute the flutter build linux command in the override-build block, otherwise execute this line of code cp -r build/linux/*/release/bundle/* $CRAFT_PART_INSTALL/ , it is possible to copy an empty file to the directory corresponding to $CRAFT_PART_INSTALL
I also want to execute the flutter build linux command in the override-build block, but I face two problems:
As you said in the discord channel, First it builds flutter in the pull stage, but I donât know about the built-in environment variables(such as the installation directory of flutter) and how to get the value of the plug-inâs configuration parameters (such as flutter-target) in the build stage, and I didnât find the documentation so I canât run the flutter script
I need to get the environment variables from the CI/CD system and then pass them to the flutter build linux command. How do I get the environment variables in CI/CD in the override-build block? Taking GitHub Actions as an example, does it look like this?
1.1ăIn the âoverride-buildâ block, I can get all the environment variables by executing the âenvâ command. I also found that the flutter installation directory has been added to the path, but when executing âflutter build linuxâ, the error âflutter: command not foundâ is reported.
1.2ăI configured âparts.app_name.flutter-targetâ in âsnapcraft.yamlâ, so how can I get this value in the âoverride-buildâ block? I didnât find a solution in the document link you gave me.
2ăThis canât be written in plain text in a config file, because my project is open source. itâs not static, so âbuild-environmentâ doesnât work, Iâve tried that.
1.1 - Does flutter installation is set in user .profile/.bashrc? If so, you need to source it within override-build
2. It can be generated on the fly with some simple scripting eventually.