I tried to create a release for a Flutter Desktop application but it was not straightforward… I created a release for Windows but not for Linux due to an error.
Linux
I followed the official steps to release a Flutter application for Linux. I run into some problems and haven’t found a solution.
Package ‘snapd’ has no installation candidate on Linux Mint
When I tried to install snap, it was not possible to install it.
$ sudo snap install snapcraft --classic
sudo: snap: command not found
$ snap
Command 'snap' not found, but can be installed with:
sudo apt install snapd
$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package snapd is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'snapd' has no installation candidate
It seems /etc/apt/preferences.d/nosnap.pref
needs to be either deleted or modified to install snap. Installing snap is not allowed by default.
The content of the file is the following.
$ cat /etc/apt/preferences.d/nosnap.pref
# To prevent repository packages from triggering the installation of Snap,
# this file forbids snapd from being installed by APT.
# For more information: https://linuxmint-user-guide.readthedocs.io/en/latest/snap.html
Package: snapd
Pin: release a=*
Pin-Priority: -10
I commented out the three lines.
# Package: snapd
# Pin: release a=*
# Pin-Priority: -10
The installation for snap succeeded.
~$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
freeglut3 gimp-data javascript-common libamd2 libbabl-0.1-0 libcamd2
libccolamd2 libcholmod3 libgegl-0.4-0 libgegl-common libgimp2.0
libglib2.0-cil libgtk2.0-cil libjs-jquery libjs-sphinxdoc libjs-underscore
liblept5 libmagick++-6.q16-8 libmetis5 libmng2 libmono-addins-gui0.2-cil
libmono-addins0.2-cil libmono-cairo4.0-cil libmono-sharpzip4.84-cil
libopencv-calib3d4.5d libopencv-contrib4.5d libopencv-dnn4.5d
libopencv-features2d4.5d libopencv-flann4.5d libopencv-highgui4.5d
libopencv-ml4.5d libopencv-objdetect4.5d libopencv-video4.5d
libopenshot-audio9 libopenshot23 libpython3-dev libpython3.10-dev
libqt5opengl5 libqt5positioning5 libqt5webchannel5 libqt5webengine-data
libqt5webengine5 libqt5webenginecore5 libqt5webenginewidgets5 libre2-9
libtesseract4 libumfpack5 libwmf0.2-7 linux-headers-5.15.0-56
linux-headers-5.15.0-56-generic linux-headers-5.15.0-57
linux-headers-5.15.0-57-generic linux-image-5.15.0-56-generic
linux-image-5.15.0-57-generic linux-modules-5.15.0-56-generic
linux-modules-5.15.0-57-generic linux-modules-extra-5.15.0-56-generic
linux-modules-extra-5.15.0-57-generic python3-defusedxml python3-dev
python3-opengl python3-py python3-pyqt5.qtopengl python3-pyqt5.qtsvg
python3-pyqt5.qtwebchannel python3-pyqt5.qtwebengine
python3-pyqt5.qtx11extras python3-sentry-sdk python3-simplejson python3-zmq
python3.10-dev
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
snapd
0 upgraded, 1 newly installed, 0 to remove and 117 not upgraded.
Need to get 23,8 MB of archives.
After this operation, 102 MB of additional disk space will be used.
Get:1 http://ftp.uni-mainz.de/ubuntu jammy-updates/main amd64 snapd amd64 2.58+22.04 [23,8 MB]
Fetched 23,8 MB in 2s (11,6 MB/s)
Selecting previously unselected package snapd.
(Reading database ... 508155 files and directories currently installed.)
Preparing to unpack .../snapd_2.58+22.04_amd64.deb ...
Unpacking snapd (2.58+22.04) ...
Setting up snapd (2.58+22.04) ...
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.aa-prompt-list
ener.service → /lib/systemd/system/snapd.aa-prompt-listener.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.apparmor.servi
ce → /lib/systemd/system/snapd.apparmor.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.autoimport.ser
vice → /lib/systemd/system/snapd.autoimport.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.core-fixup.ser
vice → /lib/systemd/system/snapd.core-fixup.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.recovery-choos
er-trigger.service → /lib/systemd/system/snapd.recovery-chooser-trigger.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.seeded.service
→ /lib/systemd/system/snapd.seeded.service.
Created symlink /etc/systemd/system/cloud-final.service.wants/snapd.seeded.servi
ce → /lib/systemd/system/snapd.seeded.service.
Unit /lib/systemd/system/snapd.seeded.service is added as a dependency to a non-
existent unit cloud-final.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.service → /lib
/systemd/system/snapd.service.
Created symlink /etc/systemd/system/timers.target.wants/snapd.snap-repair.timer
→ /lib/systemd/system/snapd.snap-repair.timer.
Created symlink /etc/systemd/system/sockets.target.wants/snapd.socket → /lib/sys
temd/system/snapd.socket.
Created symlink /etc/systemd/system/final.target.wants/snapd.system-shutdown.ser
vice → /lib/systemd/system/snapd.system-shutdown.service.
snapd.failure.service is a disabled or a static unit, not starting it.
snapd.mounts-pre.target is a disabled or a static unit, not starting it.
snapd.mounts.target is a disabled or a static unit, not starting it.
snapd.snap-repair.service is a disabled or a static unit, not starting it.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26+mint1+vanessa) ...
Okay. I installed snapcraft and multipass too.
$ sudo snap install snapcraft --classic
snapcraft 7.2.9 from Canonical✓ installed
$ sudo snap install multipass --classic
Setup snap "snapd" (18357) security profiles /
2023-03-05T08:56:52+01:00 INFO Waiting for automatic snapd restart...
Warning: flag --classic ignored for strictly confined snap multipass
multipass 1.11.0 from Canonical✓ installed
Prepare snapcraft.yaml
It’s almost the same as an example. Maybe, slots entry can be deleted.
<project root>/snap/snapcraft.yaml
name: mimij
version: 1.0.0
summary: A simple audio player
description: A simple audio player that supports AB area repeat
confinement: strict
base: core18
grade: stable
slots:
dbus-mimij: # adjust accordingly to your app name
interface: dbus
bus: session
name: com.technicalfeeder.mimij # adjust accordingly to your app name and
apps:
mimij:
command: mimij
extensions: [flutter-master] # Where "master" defines which Flutter channel to use for the build
plugs:
- network
slots:
- dbus-mimij
parts:
mimij:
source: .
plugin: flutter
flutter-target: lib/main.dart # The main entry-point file of the application
Prepare an icon for the application
<project root>/snap/gui/mimij.desktop
[Desktop Entry]
Name=mimij
Comment=A simple audio player that supports AB repeat
Exec=mimij
Icon=${SNAP}/meta/gui/mimij.png # replace name to your app name
Terminal=false
Type=Application
Categories=Music and Audio; #adjust accordingly your snap category
I prepared an icon that is 256 * 256. It seems that the size 256 * 256 is recommended for Linux.
CMake Error: The current CMakeCache.txt directory A is different than B where CMakeCache.txt was created
I executed snapcraft
command in the project directory but it threw an error.
$ snapcraft
...
[ +299 ms] CMake Error: The current CMakeCache.txt directory
/root/parts/mimij/build/build/linux/x64/release/CMakeCache.txt is different than
the directory /home/yuto/root/development/mimij/build/linux/x64/release where
CMakeCache.txt was created. This may result in binaries being created in the
wrong place. If you are not sure, reedit the CMakeCache.txt
[ +11 ms] CMake Error: The source
"/root/parts/mimij/build/linux/CMakeLists.txt" does not match the source
"/home/yuto/root/development/mimij/linux/CMakeLists.txt" used to generate cache.
Re-run cmake with a different source directory.
[ +31 ms] Building Linux application... (completed in 350ms)
[ ] "flutter linux" took 6,477ms.
[ +6 ms] Unable to generate build files
[ +1 ms]
#0 throwToolExit
(package:flutter_tools/src/base/common.dart:10:3)
#1 _runCmake
(package:flutter_tools/src/linux/build_linux.dart:152:5)
<asynchronous suspension>
#2 buildLinux
(package:flutter_tools/src/linux/build_linux.dart:73:5)
<asynchronous suspension>
#3 BuildLinuxCommand.runCommand
(package:flutter_tools/src/commands/build_linux.dart:86:5)<asynchronous suspension>
#4 FlutterCommand.run.<anonymous closure>
(package:flutter_tools/src/runner/flutter_command.dart:1308:27)
<asynchronous suspension>
#5 AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#6 CommandRunner.runCommand
(package:args/command_runner.dart:212:13)
<asynchronous suspension>
#7 FlutterCommandRunner.runCommand.<anonymous closure>
(package:flutter_tools/src/runner/flutter_command_runner.dart:288:9)
<asynchronous suspension>
#8 AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#9 FlutterCommandRunner.runCommand
(package:flutter_tools/src/runner/flutter_command_runner.dart:236:5)
<asynchronous suspension>
#10 run.<anonymous closure>.<anonymous closure>
(package:flutter_tools/runner.dart:64:9)
<asynchronous suspension>
#11 AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#12 main (package:flutter_tools/executable.dart:91:3)
<asynchronous suspension>
[ +29 ms] ensureAnalyticsSent: 27ms
[ ] Running 0 shutdown hooks
[ ] Shutdown hooks complete
[ ] exiting with code 1
Failed to run 'flutter build linux --release -v -t lib/main.dart' for 'mimij': Exited with code 1.
Verify that the part is using the correct parameters and try again.
I tried the command again after cleaning up.
$ snapcraft clean mimij
Launching a VM.
snap "core18" has no updates available
The flutter plugin is currently in beta, its API may break. Use at your own risk.
Cleaning pull step (and all subsequent steps) for mimij
Cleaning up staging area
$ snapcraft clean
But it still doesn’t work…
I tried to use LXD instead! It returns an error for the first time.
$ snapcraft --use-lxd
The 'snap' directory is meant specifically for snapcraft, but it contains the following non-snapcraft-related paths, which is unsupported and will cause unexpected behavior:
- snapcraft copy.yaml
If you must store these files within the 'snap' directory, move them to 'snap/local', which is ignored by snapcraft.
An error occurred when trying to communicate with the 'LXD' provider: cannot connect to the LXD socket ('/var/snap/lxd/common/lxd/unix.socket')..
I followed the official site and added my user to the lxd group.
$ sudo snap install lxd
$ sudo lxd init
$ sudo usermod -a -G lxd yuto
$ newgrp lxd
$ snapcraft --use-lxd
However, it doesn’t work as expected.
Hmm…
I gave up.
Windows
I first needed to install Visual Studio 2022 with the necessary components. I executed flutter build windows
but ran into an error. I didn’t copy the error but it’s something like this.
Nuget.exe not found, trying to download or use cached version.
Download NuGet
It seems that nuget is not installed automatically by Visual Studio. I downloaded from the official web site and put the exe file to flutter home. I guess you can check the path by showing Windows variable $PATH
. Put nuget.exe
to <flutter_home>\tools\bin
.
Then, I got the following error.
$ flutter build windows
Package 'Microsoft.Windows.ImplementationLibrary 1.0.210803.1' is not found in t
he following primary source(s): 'C:\Program Files (x86)\Microsoft SDKs\NuGetPack
ages\'. Please verify all your online package sources are available (OR) package
id, version are specified correctly.
CMake Error at flutter/ephemeral/.plugin_symlinks/audioplayers_windows/windows/C
MakeLists.txt:29 (message):
Failed to install nuget package
Microsoft.Windows.ImplementationLibrary.1.0.210803.1
Add a package source
I didn’t set up the package source. Add a new package source in NuGet manager. The menu name might be different because my language setting is Japanese but I guess you can reach the desired screen.
- Open Visual Studio
- Tools > Nuget package manager > Package manager settings
- NuGet package manager > Package source
- Add new package source
https://api.nuget.org/v3/index.json
I got the following error for the first time.
$ flutter build windows
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: �R�}���h "setlocal [...\mimij\build\windows\INSTALL.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -DBUILD_TYPE=Release -P cmake_install.cmake [C:\Root\Data\Progra
mming\Flutter\mimij\build\windows\INSTALL.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.ppCommon.targets(159,5): error MSB3073: if %errorlevel% neq 0 goto:cmEnd [...\mimij\build\windows\INSTALL.vcxproj]C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: :cmEnd [...\mimij\build\windows\INSTALL.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone [...\mimij\build\windows\INSTALL.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: :cmErrorLevel [...\mimij\build\windows\INSTALL.vcxproj]C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: exit /b %1 [...\mimij\build\windows\INSTALL.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: :cmDone [...\mimij\build\windows\INSTALL.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: if %errorlevel% neq 0 goto:VCEnd [...\mimij\build\windows\INSTALL.vcxproj]C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(159,5): error MSB3073: :VCEnd" �̓R�[�h 1 �ŏI�����܂����B [...\mimij\build\windows\INSTALL.vcxproj]
Building Windows application... 38.2s
Build process failed.
But it succeeded when I executed the same command after flutter clean
.
The application can be registered to Microsoft App Store but the App is not such a thing. Since it requires additional work, I stopped here. I just created a zip file and uploaded it to GitHub.
Comments