Package Flutter Linux App Into AppImage Part 2
Tags: flutter, appimage, linux, opensource
Published: 2021-07-05 19:30:14

---
title: Package Flutter Linux App Into AppImage Part 2
published: true
description: packaging flutter linux app into appimage using appimage-builder
tags: flutter , appimage , linux ,opensource
series: Flutter AppImage
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbpw070zj7uy4jm6pck2.jpg
---

## Now, We are ready to build our first Flutter AppImage app 🚀

Firstly , we will change our working directory to the project directory.

```bash
$ cd flutter_appimage
```

#### Then follow these steps:

1- Create folder  *`AppDir`*

```bash
$ mkdir AppDir
```

2- Generate the YAML recipe file required to build the AppImage

```bash
$ appimage-builder --generate
```

this command will prompt some questions. Here is the final output :

```bash
INFO:Generator:Searching AppDir
? ID [Eg: com.example.app]: com.example.flutter_appimage
? Application Name: Flutter AppImage
? Icon: flutter_appimage_icon
? Executable path relative to AppDir [usr/bin/app]: flutter_appimage
? Arguments [Default: $@]: $@
? Version [Eg: 1.0.0]: latest
? Update Information [Default: guess]: guess
? Architecture: x86_64
```

Now, you will notice a new file `AppImageBuilder.yml`  added to the root directory of our project.

Wait a second, What the hack this `flutter_appimage_icon` comes from 🙄🤔

Stop rubbing your head. Here is why :

- copy your favorite icon to the root directory and make sure its extension is `SVG`

- rename you icon to `flutter_appimage_icon.svg`

#### Now, let's open `AppImageBuilder.yml` and edit some stuff:

- add starting script that will delete old `AppDir`:
  
  ```yaml
  script:
   - rm -rf AppDir | true
   - mkdir AppDir
  ```

- add after bundling scripts to add the Flutter App to the bandle
  
  ```yaml
  AppDir:
    after_bundle:
    - cp build/linux/x64/release/bundle/flutter_appimage AppDir
    - cp -r build/linux/x64/release/bundle/lib/. AppDir/lib
    - cp -r build/linux/x64/release/bundle/data AppDir
    - cp flutter_appimage_icon.svg AppDir/usr/share/icons/
  ```

- Add `gtk3` required for flutter app also define the repositories  where dependencies  comes from
  
  ```yaml
    pacman:
      Architecture: x86_64
      repositories:
        core:
          - https://mirror.rackspace.com/archlinux/$repo/os/$arch
        extra:
          - https://mirror.rackspace.com/archlinux/$repo/os/$arch
      include:
        - gtk3
        - python # I don't know why we need but build fails without it  
        - perl # I don't know why we need but build fails without it
  ```

## Alright, Here is the moment we have been waiting for:

```bash
$ appimage-builder --skip-test 
```

🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁🥁.....................Voila 🥳🥳🥳🥳🥳

New file added to the root directory `Flutter AppImage-latest-x86_64.AppImage` 

Flutter Counter App packaged in AppImage.

But wait a second ...... not again 😫.

The bundled AppImage file is about 225 MB , your kidding me  😠.

I know the bundle size needs some optmization , I wil pospone this to part 3. 

#### References :

- [Flutter Application &mdash; appimage-builder 0.8.8 documentation](https://appimage-builder.readthedocs.io/en/latest/examples/flutter.html)

- [Linux install - Flutter](https://flutter.dev/docs/get-started/install/linux)

- [Build and release a Linux app to the Snap Store - Flutter](https://flutter.dev/docs/deployment/linux)

#### GitHub :

- [GitHub - hosamkora/Flutter_AppImage: Sample app for packaging Flutter Linux app into AppImage using AppImage Builder](https://github.com/hosamkora/Flutter_AppImage)