Creating Easy Windows Installers for Flutter Apps with Inno Bundle
Tags: flutter, package, windows, tutorial
Published: 2023-12-21 04:33:54

Every Flutter project follows a familiar journey: coding, designing, testing, and sharing that masterpiece with the world. That final step however differs for every platform. On Android, we used to build APK or AAB files that are either distributed as is or uploaded to Play Store. With IOS and AppStore is a similar story. But when it comes to Desktop, specifically Windows which holds ~69% of <a href="https://gs.statcounter.com/os-market-share/desktop/worldwide" target="_blank">Desktop Market share worldwide</a>, this step presents a hurdle. Enter the world of desktop Installer.

## Trying MSIX: Powerful, But My Simple EXE Cried

MSIX seemed to be the only option that stands out for building Windows Installers. The docs were a treat. But when crafting the Installer for my client, the complexity left me scratching my head.

It's a great pick for those targeting Microsoft Store, for its customization and adhering to Windows Standards. My biggest pain with it was the Signed certificates! Unfortunately, Windows Home edition (my case) doesn't allow creating certificates, yet they are required (Security measures) for other users to be able to use my installer, and the commands to generate them are not friendly at all. The decision was made to look for alternatives, to find none, so I had to create one.

## Welcome Inno Bundle
Inno Bundle is a command-line tool that simplifies bundling your app into an EXE installer for Microsoft Windows. The package will figure out the metadata like app version and description, etc. With friendly customizability, and easy steps to follow.

### 1. Download Inno Setup

- Option 1: Using winget

```ps
winget install -e --id JRSoftware.InnoSetup
```

- Option 2: Download installer from website

Visit <a href="https://jrsoftware.org/isdl.php" target="_blank">the official Inno Setup website</a>.
Download the latest version (tested with 6.2.2) and install it on your machine.

### 2. Add `inno_bundle` package to your project

```sh
dart pub add dev:inno_bundle
```

### 3. Give Your App a Unique Identity

To generate a random id run:

```shell
dart run inno_bundle:id
```

Or base it upon a namespace:

```shell
dart run inno_bundle:id --ns "www.example.com"
```

The output id is going to be something similar to this:

> f887d5f0-4690-1e07-8efc-d16ea7711bfb

Copy & Paste the output to your `pubspec.yaml` as shown in the next step. 

### 4. Set up the Configuration

Add your configuration to your `pubspec.yaml`. example:

```yaml
inno_bundle:
 id: f887d5f0-4690-1e07-8efc-d16ea7711bfb # <-- Put your own generated id here
 publisher: Your Name # Optional, but recommended.
```

> Make sure you do not change your id after first deployment, if you do, when the end-user tries to update your app, his machine will recognize the update as a different app due to different AppId, he will have later to uninstall the old version manually.

### 5. Build Time

With configuration in place, let the magic happen:

```shell
dart run inno_bundle:build --release
```
The command will build the app, then build the installer. The installer should generate on `<project-dir>\build\windows\x64\installer\Release` folder.

## Additional Feature
All flutter apps on windows face an issue to run on end users machine that are missing MS C++ Visual Redistributable. The issue will appear as some DLL files missing:
![vcruntime140d.dll is missing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbvex3sexv2c7vto6mk8.png)
These DLL files `msvcp140.dll`, `vcruntime140.dll`, `vcruntime140_1.dll` are also bundled automatically with the app when creating the installer, saving you a precious time.

For more customized installer, checkout <a href="https://github.com/hahouari/inno_bundle#other-configuration-examples" target="_blank">available attributes</a>, and <a href="https://github.com/hahouari/inno_bundle#other-configuration-examples" target="_blank">other configuration examples</a>.


That's it! Hope this package provides better experience to Flutter developers. If you find it useful please hit the ❤️ button
Cheers.

## About the Author

A Flutter and Web apps developer, Member of Web development team, and a lead developer on Flutter team. Giving back to community on free time. Answering for the unaddressed, for the sake of a shared future.