flet: `flet build` gives "OSError: [WinError 193] %1 is not a valid Win32 application" for some users

Description

Code example to reproduce the issue:

from flet import *


def main(page: Page):
    page.window_width = 428

    search_bar = SearchBar(
        view_elevation=2,
        view_bgcolor='gray',
        bar_overlay_color='white',
        bar_hint_text='Search...',

        bar_leading=IconButton(icon='search')
    )
    page.add(
       Column([
           search_bar
       ])
    )


app(main)

Describe the results you received:

Describe the results you expected: Expect my code to be built to an APK file after going through the process described in the documentation

Additional information you deem important (e.g. issue happens only occasionally):

Flet version (pip show flet): Version: 0.18.0

Generating app icons...Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\HomePC\AppData\Roaming\Python\Python312\Scripts\flet.exe\__main__.py", line 7, in <module>
  File "C:\Users\HomePC\AppData\Roaming\Python\Python312\site-packages\flet\cli\cli.py", line 83, in main
    args.handler(args)
  File "C:\Users\HomePC\AppData\Roaming\Python\Python312\site-packages\flet\cli\commands\build.py", line 515, in handle
    icons_result = self.run(
                   ^^^^^^^^^
  File "C:\Users\HomePC\AppData\Roaming\Python\Python312\site-packages\flet\cli\commands\build.py", line 701, in run
    r = subprocess.run(
        ^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Program Files\Python312\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 193] %1 is not a valid Win32 application

Operating system: Windows 11

Additional environment details:

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Comments: 20 (8 by maintainers)

Commits related to this issue

Most upvoted comments

OK, another challenge 😃 Whoever has flutter.file files in Flutter bin folder can you run this command please:

python -c "import shutil; print(shutil.which('flutter'))"

I encoutnered the same issue. This is caused by how the flutter and dart SDK are named. I fixed it by renaming the dart and flutter batch file in the bin folder in flutter sdk to something else.

Navigate to the directory where flutter is downloaded, for me it was D:\flutter Then, navigate into the bin folder where you’ll find two batch files, dart.bat and flutter.bat along with dart.file and flutter.file. Rename these two .file into something else, say dart_file and flutter_file and the error should be resolved.