Closed16

Fletで作ったアプリを実行可能ファイルにパッケージ化したい (Windows)

mhmh

以下のページから flutter_windows_3.19.3-stable.zip をダウンロードした。
https://docs.flutter.dev/get-started/install/windows/desktop?tab=download#install-the-flutter-sdk

zipファイルを解凍したものを C:\Users\<UserName>\AppData\Local に配置し、以下を環境変数PATHに追加した。

  • C:\Users\<UserName>\AppData\Local\flutter\bin

PATHが通っていることも確認した。

$ which flutter
/c/Users/<UserName>/AppData/Local/flutter/bin/flutter
mhmh

flet build で実行可能ファイルを作成する場合、ディレクトリ構成が決められている。
https://flet.dev/docs/guides/python/packaging-app-for-distribution/#project-structure

flet create コマンドを使うことで、そのようなディレクトリ構成のディレクトリが作成される。

$ flet create counter
Done!

Run the app:

flet run counter


$ tree
.
`-- counter
    |-- README.md
    |-- assets
    |   `-- icon.png
    |-- main.py
    `-- requirements.txt

2 directories, 4 files

$
mhmh

flet build windows を実行するとエラーになった。

$ flet build windows
Creating Flutter bootstrap project...OK
Customizing app icons and splash images...OK
Generating app icons...OK
Packaging Python app...OK
Building Windows app...
[中略]


Building with plugins requires symlink support.

Please enable Developer Mode in your system settings. Run
  start ms-settings:developers
to open settings.

Error building Flet app - see the log of failed command above.

$

Windowsで flet build を実行する場合、開発者モードを有効化しておく必要があるらしい。
https://flet.dev/docs/guides/python/packaging-app-for-distribution/#windows-requirements

mhmh

無事にビルドできた。

$ flet build windows
Creating Flutter bootstrap project...OK
Customizing app icons and splash images...OK
Generating app icons...OK
Packaging Python app...OK
Building Windows app...OK
Copying build to build\windows directory...OK
Success!

$ ls build/windows/
counter.exe*  DLLs/                 Lib/           python3.dll*    screen_retriever_plugin.dll*        url_launcher_windows_plugin.dll*  vcruntime140_1.dll*         window_to_front_plugin.dll*
data/         flutter_windows.dll*  msvcp140.dll*  python311.dll*  serious_python_windows_plugin.dll*  vcruntime140.dll*                 window_manager_plugin.dll*
mhmh

ディレクトリ全体のサイズは189MBだった。

$ du -sh build/windows/
189M    build/windows/
mhmh

今回の環境

$ python --version
Python 3.10.11

$ pip show flet | grep Version
Version: 0.21.1

$ flutter --version
Flutter 3.19.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ba39319843 (8 days ago) • 2024-03-07 15:22:21 -0600
Engine • revision 2e4ba9c6fb
Tools • Dart 3.3.1 • DevTools 2.31.1
mhmh

build/windows/ 配下に生成された counter.exe を実行すると、カウンターアプリが表示される。

mhmh

counter.exe のみを適当な場所にコピーし、それを実行しようとするとエラーになる。

一緒に出力された *.dll などのファイルも実行には必要であることが確認できた。

このスクラップは1ヶ月前にクローズされました