Difference between revisions of "Create snap package"
|Line 121:||Line 121:|
Revision as of 10:34, 15 December 2021
- Install snapcraft to your Ubuntu machine with sudo apt install snapcraft
- Create snap subdirectory in your project
- Execute snapcraft init to create snap/snapcraft.yaml initial file
- Example file:
name: myapp version: '1.0.0' summary: Short description of the package. description: | Some more detailed multi-line description. confinement: strict base: core20 grade: stable parts: myapp: plugin: nil source: . source-type: local build-packages: - fpc - lazarus - lcl - lcl-utils stage-packages: # Autodetected dependencies - libatk1.0-0 - libcairo2 - libdatrie1 - libfontconfig1 - libfreetype6 - libfribidi0 - libgdk-pixbuf2.0-0 - libgraphite2-3 - libgtk2.0-0 - libharfbuzz0b - libpango-1.0-0 - libpangocairo-1.0-0 - libpangoft2-1.0-0 - libpixman-1-0 - libpng16-16 - libthai0 - libx11-6 - libxau6 - libxcb-render0 - libxcb-shm0 - libxcb1 - libxcomposite1 - libxcursor1 - libxdamage1 - libxdmcp6 - libxext6 - libxfixes3 - libxi6 - libxinerama1 - libxrandr2 - libxrender1 override-build: | lazbuild --build-mode=Release myapp.lpi install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/myapp install -s -m 755 myapp $SNAPCRAFT_PART_INSTALL/usr/share/myapp install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/applications install -m 755 Install/deb/myapp.desktop $SNAPCRAFT_PART_INSTALL/usr/share/applications stage: - etc - lib - usr - usr/share/myapp - usr/share/applications/myapp.desktop apps: myapp: command: usr/share/myapp/myapp desktop: usr/share/applications/myapp.desktop plugs: - home - desktop - x11
- See Snapcraft.yaml reference for full list of supported properties.
- Lazarus still uses old Gtk2 libraries. See GTK2 Applications page.
- Sample snapcraft.yaml files using lazbuild on Github
- Build snap using snapcraft command
- Install newly created snap with sudo snap install --dangerous myapp_1.0.0_amd64.snap
Publish your package in Snap Store
snapcraft upload myapp.snap
snapcraft release myapp 1 stable
- Now your snap should be released and available on snapcraft.io store.
To get to console of snap virtual filesystem use:
snap run --shell myapp cd $SNAP
Type exit to leave snap environment. See Debugging snaps for more information.
Use newer Lazarus version
Normally you can use Lazarus IDE version provided by current base (2.0.6 for core20). To use latest stable version with new features you can add following part into your snapcraft.yaml file. This part should be executed before myapp part. You need to update fixed URL based on required Lazarus version. Then those packages will be downloaded and installed before build.
parts: lazarus: plugin: nil source: . source-type: local build-packages: - wget - libgtk2.0-dev override-build: | wget -nc https://deac-ams.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.12/lazarus-project_2.0.12-0_amd64.deb wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.12/fpc-laz_3.2.0-1_amd64.deb wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.12/fpc-src_3.2.0-1_amd64.deb apt install ./lazarus-project_2.0.12-0_amd64.deb ./fpc-laz_3.2.0-1_amd64.deb ./fpc-src_3.2.0-1_amd64.deb prime: [-*] myapp: after: [lazarus]
And remove normal Lazarus build-packages from your app so they are not installed for build:
myapp build-packages: - fpc - lazarus - lcl - lcl-utils
Snap supports sound through audio-playback plug.
apps: myapp: plugs: - audio-playback
You can play wav and mp3 files from command line using play command. See Play Sound Multiplatform. Then you also need to add additional stage-packages to myapp part and setup sox player for pulseaudio:
parts: myapp: stage-packages: - sox - libsox-fmt-mp3 - libsox-fmt-pulse - libpulse0 environment: LD_LIBRARY_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio PULSE_SERVER: unix:/run/user/1000/pulse/native layout: /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox: bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox
snapcraft.yaml file in non-standard subdirectory
Snapcraft normally expect snapcraft.yaml file in snap directory. If your project has packaging for multiple other packaging formats, then you need to use build workaround script. Such shell script can put into directory like myapp/install/snap/local as build.sh file.
#!/bin/bash ln -s install/snap ../../../snap pushd ../../.. snapcraft popd rm ../../../snap
Register app in snap store
- Login into https://snapcraft.io with your user account
- Register new snap package name https://snapcraft.io/account/register-snap
- Go to your newly registered package and fill all needed details https://snapcraft.io/snaps
Setup build on Launchpad
Snap packages can be built automatically on Launchpad. Open Create snap package link form your application branch page.