Is it possible to generate linux .rpm packages from flutter linux app?

474

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.

  1. Create a Dockerfile which in which we will install the rpm-build package which contains all tools to build RPMs.
FROM centos:7

RUN yum install -y -q rpm-build
  1. Build this dockerfile and remember the docker image, we will need it later.
  2. Execute the following command mkdir -p build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}. This will create the directory structure required for rpmbuild
  3. Create a .spec file, this file is a config file for the rpmbuild command and place it in the build/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.
  4. Download the files you want to package, often they are distributed as tarballs and place it in the build/SOURCES directory.
  5. 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 the build 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 the docker command and not passed to the container.
  • "cd /rpmbuild && rpmbuild --define '_topdir /rpmbuild' -ba SPECS/flutter.spec" - move to the mounted build directory and build the RPM package. the -ba option tells rpmbuild to build both the binary and source packages in case you want the source package as well.
  1. If all went well your should now have an .rpm file in the build/RPMS and a source package in the build/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)

Share:
474
avimehenwal
Author by

avimehenwal

Updated on December 06, 2022

Comments

  • avimehenwal
    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
    Dolphin over 2 years
    It is too complex to do like that, seems hard to to like that. @caveman
  • Dylan Reimerink
    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
    Dolphin over 2 years
    I 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