User:Gromit/Flutter package guidelines

From ArchWiki
Arch package guidelines

32-bitCLRCMakeCrossDKMSEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernelLispMesonMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRustShellVCSWebWine

This document covers standards and guidelines on writing PKGBUILDs for Flutter.

This article or section needs expansion.

Reason:

This is still very much unfinished and there are a lot of missing things here

  • I did not find a (working) way of installing the resulting binaries to /usr/
  • Add well written PKGBUILDs to the Example Packages section
  • How can flutter packages be built in clean chroot?
  • Is there a global setting for --no-version-check?
  • Did we miss other stuff regarding telemetry or build options?
(Discuss in User talk:Gromit/Flutter package guidelines)

Building

Desktop dependencies

Flutter requires several dependencies to build desktop apps, these dependencies include:

These should be set in makedepends array of the package.

Sample PKGBUILD

pkgname=flutter-default-linux-app
pkgver=3.10.2
pkgrel=1
pkgdesc='Example PKGBUILD for a flutter linux app'
arch=('x86_64')
url="https://docs.flutter.dev/"
depends=('gtk3')
makedepends=('flutter' 'clang' 'cmake' 'ninja' 'pkgconf' 'xz')
source=("https://github.com/christian-heusel/flutter-default-linux-app/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('c07ab021cb11ce79076ab805b8507d3782d714d70b3bd5f26b2e927cdddf5f0c')

prepare(){
    cd "$pkgname-$pkgver"
    flutter --no-version-check config --no-analytics
    flutter --no-version-check config --enable-linux-desktop
    flutter --no-version-check pub get
}

build() {
    cd "$pkgname-$pkgver"
    flutter --no-version-check build linux --release
}

package() {
    cd "$pkgname-$pkgver/build/linux/x64/release/bundle/"
    # create the target folders
    install -dm 755 "$pkgdir/opt/$pkgname" "$pkgdir/usr/bin/"
    # copy the bundled output to /opt
    cp -rdp --no-preserve=ownership . "$pkgdir/opt/$pkgname/"
    # symlink to /usr/bin so the app can be found in PATH
    ln -s "/opt/$pkgname/flutterapp" "$pkgdir/usr/bin/$pkgname"
}

Example packages

Saber

Saber is a cross platform note taking app, the package contains a few complications which makes it a good example:

  • Uses native libraries written in Rust, Flutter explicitly checks for the rustup binary, therefore rustup must be used instead of rust.
  • Written in Flutter

Links

  • AURWeb - details on the package.
  • AUR cgit - to view the saber PKGBUILD.
  • Github issue - to view the development process of the package, with help from upstream, and other Arch Users which tested the package before it was pushed to the AUR.
  • External git repository - used for development and maintenance of the saber package, and issues should also be reported here.

Known issues

Ownership problems, or permission denial

If you get an error where you do not have permission to build flutter packages, run the following command:

$ flutter doctor

This will check if flutter is encountering any issues, most likely you will see the following error:

detected dubious ownership in repository at '/opt/flutter'

To fix this problem, run the following command:

$ git config --global --add safe.directory /opt/flutter

This is a known issue with flutterAUR which has not yet been fixed.

Troubleshooting

Loader fails to find shared object (.so) files

If you attempt to run a flutter application, and the loader states that some_library.so can not be found, please follow the steps below.

Example error:

saber: error while loading shared libraries: libsuper_native_extensions.so: cannot open shared object file: No such file or directory

This error occurs due to the loader attempting to find the libraries within the usual (/usr/lib) or other wrong paths, however the libraries are stored within the flutter bundle next to the executable.

To fix this, execute the package by setting the LD_LIBRARY_PATH to the path of the lib directory within the flutter bundle, see an example launcher script below:

#!/bin/bash
LD_LIBRARY=/opt/pkgname/lib /opt/pkgname/pkgname "$@"

See also