How to Develop Linux Applications (Part 2)
Tags: linux, todayilearned, todayisearched
Published: 2022-05-07 03:51:02

## Table of Contents <a name="TOC">
1. [AppCenter Dashboard](#appcenter-dashboard)
2. [AppImage](#appimage)
3. [Flatpak](#flatpak)
4. [Snapcraft](#snapcraft)
5. [Helpful Links](#helpful-links)


### [AppCenter Dashboard](https://developer.elementary.io/)
> - New apps get featured with a large, branded banner. Plus, trending and recently-updated apps are featured on the front page.
> - Define your app's keywords, categories, and subcategories to help people find it.
> - With built-in social media sharing and app URLs, users can easily share your app right from AppCenter.

You need to make sure you prefix your `Application.vala` file in your `src` folder and that it matches your license of your code and assigns copyright to you.
```
/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2021 Your Name <you@email.com>
 */
```

Your MetaInfo file will contain all the information needed to list your app in AppCenter and will look something like:
```
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
  <id>com.github.myteam.myapp</id>

  <name>My App</name>
  <summary>Proves that we can use Vala and Gtk</summary>

  <metadata_license>CC-BY-4.0</metadata_license>
  <project_license>GPL-3.0-or-later</project_license>

  <description>
    <p>
      A quick summary of your app's main selling points and features. Just a couple sentences per paragraph is best
    </p>
  </description>

  <launchable type="desktop-id">com.github.myteam.myapp.desktop</launchable>
</component>
```

Your desktop entry file will contain all the information needed to display your app in the applications menu as well as the dock and should look something like this:
```
[Desktop Entry]
Version=1.0
Type=Application

Name=My App
Comment=Proves that we can use Vala and Gtk
Categories=Development;Education;

Icon=com.github.myteam.myapp
Exec=com.github.myteam.myapp
Terminal=false
```

Check [Our First App](https://docs.elementary.io/develop/writing-apps/our-first-app#the-desktop-file) here for the rest of the code and full explanation and details.

[Back to TOC](#TOC)

### AppImage
Distribute your desktop Linux application in the AppImage format and win users running all common Linux distributions.

> appimage-builder is a novel tool for creating AppImages. It uses the system package manager to resolve the application dependencies and creates a complete bundle. It can be used to pack almost any kind of applications including those made using: C/C++, Python, and Java.

There are [tutorials](https://appimage-builder.readthedocs.io/en/latest/intro/tutorial.html) as well as [troubleshooting](https://appimage-builder.readthedocs.io/en/latest/advanced/troubleshooting.html) documentation for more information. 

{% embed https://www.youtube.com/watch?v=2OO3KY6dWVU %}

#### How to Install appimage-builder
Option 1: AppImage for amd64 systems
```
wget -O appimage-builder-x86_64.AppImage https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.0.0-beta.1/appimage-builder-1.0.0-677acbd-x86_64.AppImage
chmod +x appimage-builder-x86_64.AppImage

# install (optional)
sudo mv appimage-builder-x86_64.AppImage /usr/local/bin/appimage-builder
```

Option 2: Docker Image
> NOTE: Testing AppImages is not supported on this format. Always use –skip-test.

```
docker pull appimagecrafters/appimage-builder:latest
```

Option 3: Manual Installation
> The project is built using Python 3 and uses various command-line applications to fulfill its goal. Depending on the host system and the recipe the packages providing such applications may vary.

Step 1: Installing dependencies
**Debian/Ubuntu**
```
sudo apt install -y python3-pip python3-setuptools patchelf desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace fuse

# Install appimagetool AppImage
sudo wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O /usr/local/bin/appimagetool
sudo chmod +x /usr/local/bin/appimagetool
```

**Arch Linux**
```
sudo pacman -Sy python-pip python-setuptools binutils patchelf desktop-file-utils gdk-pixbuf2 wget fakeroot strace

# Install appimagetool AppImage
sudo wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O /usr/local/bin/appimagetool
sudo chmod +x /usr/local/bin/appimagetool
```

Step 2: Installing appimage-builder
Option 1: Installing latest tagged release:
```
sudo pip3 install appimage-builder
```

Option 2: Installing development version:
```
sudo pip3 install git+https://github.com/AppImageCrafters/appimage-builder.git
```

Step 3: Install appimagetool
> There is an issue in the AppImage runtime format that prevents it proper execution inside docker containers. Therefore we must use the following workaround to make appimagetool work properly.

```
# Install appimagetool AppImage
sudo wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O /opt/appimagetool

# workaround AppImage issues with Docker
cd /opt/; sudo chmod +x appimagetool; sed -i 's|AI\x02|\x00\x00\x00|' appimagetool; sudo ./appimagetool --appimage-extract
sudo mv /opt/squashfs-root /opt/appimagetool.AppDir
sudo ln -s /opt/appimagetool.AppDir/AppRun /usr/local/bin/appimagetool
```

[Back to TOC](#TOC)

### Flatpak
[Flatpak](https://flatpak.org/) is a framework for distributing desktop applications on Linux and runs as an independent open source project.

{% embed https://youtu.be/jDVCITRWGgs %}

- Build for every distro
- Develop apps compatible with new versions of Linux distributions
- Make your apps available with [Flathub](https://flathub.org/)
- Flatpak is developed by an independent community

Check their [developer guide](https://docs.flatpak.org/en/latest/) or see the number of [distros](https://flatpak.org/setup) Flatpak can be used with. 

Read the [Flatpak documentation](https://docs.flatpak.org/en/latest/) to get everything you need to know to build and distribute applications using Flatpak.

[Building your first Flatpak](https://docs.flatpak.org/en/latest/first-build.html) is a great place to start! They even have [tips and tricks](https://docs.flatpak.org/en/latest/tips-and-tricks.html)

### Snapcraft
Build and publish your snaps to the [Snap store](https://snapcraft.io/store)

> At the heart of the snapcraft build process is a file called snapcraft.yaml. This file describes a snap’s build dependencies and run-time requirements, it integrates remote repositories and extensions, and runs custom scripts and hooks for better integration with CI systems.

`snapcraft.yaml` is organized into three principle sections: top-level metadata, apps and services, and parts.

1. [top-level metadata](https://snapcraft.io/docs/snapcraft-top-level-metadata) contains values typically used by the store

	- architectures
	- assumes
	- base
	- compression
	- contact
	- description
	- hooks
	- issues
	- icon
	- layout
	- license
	- summary
	- title
	- type
	- version
	- plugs

2. [app and services](https://snapcraft.io/docs/snapcraft-app-and-service-metadata) describes how the app and services are exposed to the host system

	- adapter
	- autostart
	- command
	- command-chain
	- desktop
	- environment
	- install-mode
	- listen-stream
	- restart-condition
	- refresh-mode
	
3. [parts](https://snapcraft.io/docs/snapcraft-parts-metadata) describes how to import and build each required part of the snap

	- build-attributes
	- build-snaps
	- organize
	- parse-info
	- source
	- stage

For more information, check [documentation guidelines](https://snapcraft.io/docs/documentation-guidelines), [installing snapd](https://snapcraft.io/docs/installing-snapd), [releasing your app](https://snapcraft.io/docs/releasing-your-app), [managing snaps](https://snapcraft.io/docs/commands-and-aliases), and [troubleshooting](https://snapcraft.io/docs/troubleshooting).

[Back to TOC](#TOC)

### Helpful Links
- [Building Introduction with Flatpak](https://docs.flatpak.org/en/latest/building-introduction.html)
- [Publishing with Flatpak](https://docs.flatpak.org/en/latest/publishing.html)
- [Creating snapcraft.yaml](https://snapcraft.io/docs/creating-snapcraft-yaml)
- [Getting started with snapcraft](https://snapcraft.io/docs/getting-started)

Will you become a Linux app developer?

Happy coding!