Is it possible to generate linux .rpm packages from flutter linux app?
Building RPMs and DEBs is doable, but a pretty involved process. I will try to outline the basic process for RPM's as best as I can. The process of making a DEB is mostly the same with a few differences. I will stick to RPM's for now.
The main thing which is a pain is that to build packages you need specific tools which are only available on the distros. So if you want to do this cross platform (generate a RPM on a ubuntu machine for example) we need to use Docker.
- Create a
Dockerfile
which in which we will install therpm-build
package which contains all tools to build RPMs.
FROM centos:7
RUN yum install -y -q rpm-build
- Build this dockerfile and remember the docker image, we will need it later.
- Execute the following command
mkdir -p build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
. This will create the directory structure required forrpmbuild
- Create a .spec file, this file is a config file for the
rpmbuild
command and place it in thebuild/SPECS
directory. The contents of this file are very specific to the what the package has to do. RPMs are very flexible and can do lots of stuff ranging from just copying files to running complex bash scripts on the target machine to perform compilation on the target machine and perform complex installations. Here are some guides which I found useful: package guide, fedora guide, and redhat guide. - Download the files you want to package, often they are distributed as tarballs and place it in the
build/SOURCES
directory. - Now we can execute the following command
docker run --rm -v $(pwd)/build:/rpmbuild {name of image} /bin/bash -c "cd /rpmbuild && rpmbuild --define '_topdir /rpmbuild' -ba SPECS/flutter.spec"
I will break the command down.
-
docker run --rm -v $(pwd)/build:/rpmbuild {name of image}
- we start a container from the image we created earlier, and mount thebuild
dir in which our .spec and .tar.gz are located so the container can see them.--rm
cleans up the container after we are done since we don't need it after the first command. -
/bin/bash -c
- this is a trick since we need to execute 2 command inside the docker container, if we don't do this our shell will thing the&&
is meant after thedocker
command and not passed to the container. -
"cd /rpmbuild && rpmbuild --define '_topdir /rpmbuild' -ba SPECS/flutter.spec"
- move to the mountedbuild
directory and build the RPM package. the-ba
option tellsrpmbuild
to build both the binary and source packages in case you want the source package as well.
- If all went well your should now have an .rpm file in the
build/RPMS
and a source package in thebuild/SRPMS
directory.
For DEB the process is almost the same, except you need a debian or ubuntu docker image, you use the dpkg-deb
command to build and you need a control
file instead of a .spec file(same purpose different format)
avimehenwal
Updated on December 06, 2022Comments
-
avimehenwal over 1 year
As far as I know, Flutter for linux app only targets
snap
packaging format.Is it possible to generate
.rpm
and.deb
(cross-linux platform) software packages from the flutter build?Kindly post any help on how to package a flutter-linux app as RPM package
-
Dolphin over 2 yearsIt is too complex to do like that, seems hard to to like that. @caveman
-
Dylan Reimerink over 2 years@Dolphin, can you give us some links to guides or tutorials that show us how to do this better? If there is some better way to do it without having to setup a dedicated build server per platform I would love to know since that would make my live easier.
-
Dolphin over 2 yearsI am glad to show a better way to package flutter package in liunx, but I have to say, I did not found or search a easy way to do this. I am learning to package in github actions to package into appImage or Flatpack or Snap package. @caveman