flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.45k stars 446 forks source link

Not able to build a Flet Counter app into APK format on Windows 11 #4052

Closed TheCodeCache closed 3 weeks ago

TheCodeCache commented 1 month ago

Hi,

I've been trying to build a very simple flet counter app to APK file, but it stucks at the same place everytime. I've verified all the configuration as per the these docs : doc1, doc2, doc3, and verified all the installations, yet it fails to build and gets stuck after installing the dependencies. Please find below steps that I performed:

I'm running these steps on my local Windows 11, with 12 GB of RAM and 256 of SSD capacity.

Step 0: Install java 8 and verify its version:

C:\Users\manor>java -version
java version "1.8.0_333"
Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode)

Step 1: Install Flutter (latest 3.24.3) and verify its version:

C:\Users\manor>flutter --version
Flutter 3.24.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2663184aa7 (2 weeks ago) • 2024-09-11 16:27:48 -0500
Engine • revision 36335019a8
Tools • Dart 3.5.3 • DevTools 2.37.3

Step 2: Install Android Studio (latest Koala 2024.1.2) and installed all these components:

Android SDK Platform, API 35.0.1
Android SDK Command-line Tools
Android SDK Build-Tools
Android SDK Platform-Tools

Step 3: Configure below Environment Variables into both user path as well as system path:

C:\Users\manor\dev\flutter\bin
C:\Users\manor\AppData\Local\Android\Sdk\cmdline-tools\latest\bin
C:\Users\manor\AppData\Local\Android\Sdk\platform-tools
C:\Users\manor\AppData\Local\Android\Sdk\build-tools\35.0.0

Step 4: Verify the installation with flutter doctor,

C:\Users\manor>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Version 10.0.22631.4169], locale en-IN)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.5)
[√] Android Studio (version 2024.1)
[√] VS Code (version 1.93.1)
[√] Connected device (3 available)
[√] Network resources

• No issues found!

Step 5: Create a simple flet counter app and make sure it works:

import flet as ft

def main(page: ft.Page):
    page.title = "Flet Counter Example 1"
    page.vertical_alignment = ft.MainAxisAlignment.CENTER

    txt_number = ft.TextField(value="0", text_align=ft.TextAlign.RIGHT, width=100)

    def minus_click(e):
        txt_number.value = str(int(txt_number.value) - 1)
        page.update()

    def plus_click(e):
        txt_number.value = str(int(txt_number.value) + 1)
        page.update()

    page.add(
        ft.Row(
            [
                ft.IconButton(ft.icons.REMOVE, on_click=minus_click),
                txt_number,
                ft.IconButton(ft.icons.ADD, on_click=plus_click),
            ],
            alignment=ft.MainAxisAlignment.CENTER,
        )
    )

if __name__ == "__main__":
    ft.app(main)

Verify its output:

image

This is my code folder structure:

image

and requirements.txt file contains just one package flet and nothing else:

image

Step 6: Run the below flet build command:

flet build apk -vv

Here is the command line logs:

C:\Users\manor\Downloads\the_app\code\hi_flet>flet build apk -vv

[14:06:22] Flutter executable: C:\Users\manor\dev\flutter\bin\flutter.BAT
           Dart executable: C:\Users\manor\dev\flutter\bin\dart.BAT
           Flutter bootstrap directory: C:\Users\manor\AppData\Local\Temp\flet_flutter_build_RVzVXz8if3
           No additional Flutter dependencies!
[14:06:25] Created Flutter bootstrap project from gh:flet-dev/flet-build-template with ref 0.24.1 ✅
           Copying C:\Users\manor\Downloads\the_app\code\hi_flet\assets\icon.png to
           C:\Users\manor\AppData\Local\Temp\flet_flutter_build_RVzVXz8if3\images
           Customized app icons and splash images ✅
           Run subprocess: ['C:\\Users\\manor\\dev\\flutter\\bin\\dart.BAT', 'run', 'flutter_launcher_icons']
( ●    ) Generating app icons (2.5s)
Downloading packages...
Got dependencies in `C:\Users\manor\AppData\Local\Temp\flet_flutter_build_RVzVXz8if3`.
(     ●) Generating app icons ⏳...
Built flutter_launcher_icons:flutter_launcher_icons.
( ●    ) Generating app icons ⏳...   ════════════════════════════════════════════
     FLUTTER LAUNCHER ICONS (v0.13.1)
  ════════════════════════════════════════════

(  ●   ) Generating app icons ⏳... • Creating default icons Android
(   ●  ) Generating app icons ⏳... • Overwriting the default Android launcher icon with a new icon
(   ●  ) Generating app icons ⏳... • Overwriting default iOS launcher icon with new icon
(   ●  ) Generating app icons ⏳... Creating Icons for Web...
(  ●   ) Generating app icons ⏳... Creating Icons for Windows...
( ●    ) Generating app icons ⏳... Creating Icons for MacOS...
(     ●) Generating app icons ⏳...
✓ Successfully generated launcher icons
[14:06:32] Generated app icons ✅
           Run subprocess: ['C:\\Users\\manor\\dev\\flutter\\bin\\dart.BAT', 'run', 'flutter_native_splash:create']
( ●    ) Generating splash screens (1.5s)
Built flutter_native_splash:create.
(    ● ) Generating splash screens ⏳... [Android] Creating default splash images
(  ●   ) Generating splash screens ⏳... [Android] Creating dark mode splash images
(    ● ) Generating splash screens ⏳... [Android] Creating default android12splash images
(   ●  ) Generating splash screens ⏳... [Android] Creating dark mode android12splash images
(   ●  ) Generating splash screens ⏳... [Android] Updating launch background(s) with splash image path...
(     ●) Generating splash screens ⏳... [Android]  - android/app/src/main/res/drawable/launch_background.xml
[Android]  - android/app/src/main/res/drawable-night/launch_background.xml
[Android]  - android/app/src/main/res/drawable-v21/launch_background.xml
[Android]  - android/app/src/main/res/drawable-night-v21/launch_background.xml
[Android] Updating styles...
[Android]  - android/app/src/main/res/values-v31/styles.xml
[Android] No android/app/src/main/res/values-v31/styles.xml found in your Android project
[Android] Creating android/app/src/main/res/values-v31/styles.xml and adding it to your Android project
(   ●  ) Generating splash screens ⏳... [Android]  - android/app/src/main/res/values-night-v31/styles.xml
[Android] No android/app/src/main/res/values-night-v31/styles.xml found in your Android project
[Android] Creating android/app/src/main/res/values-night-v31/styles.xml and adding it to your Android project
[Android]  - android/app/src/main/res/values/styles.xml
[Android]  - android/app/src/main/res/values-night/styles.xml
[iOS] Creating  images
[iOS] Creating dark mode  images
(  ●   ) Generating splash screens ⏳... [iOS] Updating ios/Runner/Info.plist for status bar hidden/visible
(   ●  ) Generating splash screens ⏳... [Web] Creating images
(  ●   ) Generating splash screens ⏳... [Web] Creating images
(   ●  ) Generating splash screens ⏳... [Web] Creating background images
[Web] Creating CSS
(    ● ) Generating splash screens ⏳... [Web] Updating index.html

✅ Native splash complete.
Now go finish building something awesome! 💪 You rock! 🤘🤩
Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash

[14:06:38] Generated splash screens ✅
           Run subprocess: ['C:\\Users\\manor\\dev\\flutter\\bin\\dart.BAT', 'run', 'serious_python:main', 'package',
           'C:\\Users\\manor\\Downloads\\the_app\\code\\hi_flet', '--mobile', '--platform', 'mobile', '--dep-mappings', 'flet=flet-embed',
           '--req-deps', 'flet-embed', '--exclude', 'build', '--verbose']
(  ●   ) Packaging Python app ⏳...
Built serious_python:main.
(    ● ) Packaging Python app ⏳... Running package command
Creating asset directory: C:\Users\manor\AppData\Local\Temp\flet_flutter_build_RVzVXz8if3\app
Copying Python app from C:\Users\manor\Downloads\the_app\code\hi_flet to C:\Users\manor\AppData\Local\Temp\serious_python_tempbcaf66d7
(   ●  ) Packaging Python app ⏳... Configured mobile platform with sitecustomize.py at C:\Users\manor\AppData\Local\Temp\serious_python_sitecustomize8bdf18b8\sitecustomize.py
Installing dependencies [flet-embed] with pip command to C:\Users\manor\AppData\Local\Temp\serious_python_tempbcaf66d7\__pypackages__
Extracting Python distributive from C:\Users\manor\AppData\Local\Temp\cpython-3.11.6+20231002-x86_64-pc-windows-msvc-shared-install_only.tar.gz to C:\Users\manor\AppData\Local\Temp\hostpython3.11_36ae20a5
(  ●   ) Packaging Python app ⏳... VERBOSE: C:\Users\manor\AppData\Local\Temp\hostpython3.11_36ae20a5\python\python.exe -m pip install --isolated --upgrade --target C:\Users\manor\AppData\Local\Temp\serious_python_tempbcaf66d7\__pypackages__ flet-embed
( ●    ) Packaging Python app ⏳... VERBOSE: Collecting flet-embed
VERBOSE: Using cached flet_embed-0.24.1-py3-none-any.whl.metadata (1.0 kB)
(   ●  ) Packaging Python app ⏳... VERBOSE: Collecting flet-runtime==0.24.1 (from flet-embed)
VERBOSE: Using cached flet_runtime-0.24.1-py3-none-any.whl.metadata (1.1 kB)
(     ●) Packaging Python app ⏳... VERBOSE: Collecting flet-core==0.24.1 (from flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached flet_core-0.24.1-py3-none-any.whl.metadata (971 bytes)
(    ● ) Packaging Python app ⏳... VERBOSE: Collecting httpx<1,>=0 (from flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached httpx-0.27.2-py3-none-any.whl.metadata (7.1 kB)
(  ●   ) Packaging Python app ⏳... VERBOSE: Collecting oauthlib<4.0.0,>=3.2.2 (from flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached oauthlib-3.2.2-py3-none-any.whl.metadata (7.5 kB)
( ●    ) Packaging Python app ⏳... VERBOSE: Collecting repath<0.10.0,>=0.9.0 (from flet-core==0.24.1->flet-runtime==0.24.1->flet-embed)
(●     ) Packaging Python app ⏳... VERBOSE: Using cached repath-0.9.0-py3-none-any.whl.metadata (899 bytes)
( ●    ) Packaging Python app ⏳... VERBOSE: Collecting anyio (from httpx<1,>=0->flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached anyio-4.6.0-py3-none-any.whl.metadata (4.6 kB)
(  ●   ) Packaging Python app ⏳... VERBOSE: Collecting certifi (from httpx<1,>=0->flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
(     ●) Packaging Python app ⏳... VERBOSE: Collecting httpcore==1.* (from httpx<1,>=0->flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached httpcore-1.0.5-py3-none-any.whl.metadata (20 kB)
(    ● ) Packaging Python app ⏳... VERBOSE: Collecting idna (from httpx<1,>=0->flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached idna-3.10-py3-none-any.whl.metadata (10 kB)
(  ●   ) Packaging Python app ⏳... VERBOSE: Collecting sniffio (from httpx<1,>=0->flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached sniffio-1.3.1-py3-none-any.whl.metadata (3.9 kB)
( ●    ) Packaging Python app ⏳... VERBOSE: Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0->flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached h11-0.14.0-py3-none-any.whl.metadata (8.2 kB)
( ●    ) Packaging Python app ⏳... VERBOSE: Collecting six>=1.9.0 (from repath<0.10.0,>=0.9.0->flet-core==0.24.1->flet-runtime==0.24.1->flet-embed)
VERBOSE: Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
VERBOSE: Using cached flet_embed-0.24.1-py3-none-any.whl (3.2 kB)
VERBOSE: Using cached flet_runtime-0.24.1-py3-none-any.whl (19 kB)
VERBOSE: Using cached flet_core-0.24.1-py3-none-any.whl (412 kB)
VERBOSE: Using cached httpx-0.27.2-py3-none-any.whl (76 kB)
VERBOSE: Using cached httpcore-1.0.5-py3-none-any.whl (77 kB)
(  ●   ) Packaging Python app ⏳... VERBOSE: Using cached oauthlib-3.2.2-py3-none-any.whl (151 kB)
VERBOSE: Using cached repath-0.9.0-py3-none-any.whl (4.7 kB)
VERBOSE: Using cached anyio-4.6.0-py3-none-any.whl (89 kB)
VERBOSE: Using cached idna-3.10-py3-none-any.whl (70 kB)
VERBOSE: Using cached sniffio-1.3.1-py3-none-any.whl (10 kB)
VERBOSE: Using cached certifi-2024.8.30-py3-none-any.whl (167 kB)
VERBOSE: Using cached h11-0.14.0-py3-none-any.whl (58 kB)
VERBOSE: Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
(   ●  ) Packaging Python app ⏳... VERBOSE: Installing collected packages: sniffio, six, oauthlib, idna, h11, certifi, repath, httpcore, anyio, httpx, flet-core, flet-runtime, flet-embed
(   ●  ) Packaging Python app ⏳...

The issue is: it gets completely stuck on last step as shown above, waited for sufficiently long for about 1 hr, yet it does not move forward at all.

However, when I stop this with ctrl+C , I get below logs:

(     ●) Packaging Python app ⏳...
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\manor\Downloads\the_app\code\hi_flet\venv\Scripts\flet.exe\__main__.py", line 7, in <module>
  File "C:\Users\manor\Downloads\the_app\code\hi_flet\venv\Lib\site-packages\flet\cli\cli.py", line 88, in main
    args.handler(args)
  File "C:\Users\manor\Downloads\the_app\code\hi_flet\venv\Lib\site-packages\flet\cli\commands\build.py", line 790, in handle
    package_result = self.run(
                     ^^^^^^^^^
  File "C:\Users\manor\Downloads\the_app\code\hi_flet\venv\Lib\site-packages\flet\cli\commands\build.py", line 945, in run
    r = subprocess.run(
        ^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\subprocess.py", line 550, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\subprocess.py", line 1201, in communicate
    self.wait()
  File "C:\Program Files\Python311\Lib\subprocess.py", line 1264, in wait
    return self._wait(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\subprocess.py", line 1588, in _wait
    result = _winapi.WaitForSingleObject(self._handle,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
^C

Additionally, I've also followed these video resources from youtube in order to resolve above issue, but no luck

link1, link2, link3, link4, link5

Please help, Would really appreciate

zox47 commented 1 month ago

try this python -m pip install --upgrade pip pip install --upgrade setuptools wheel

and build again

tanmay-bhatgare commented 1 month ago

Idk about the error but if you want to build your app, here's a solution for it.

OwenMcDonnell commented 1 month ago

I've gone through the steps you outlined on a Windows 11 machine but could not reproduce the error. Can you try updating to Python 3.12 and run the same steps and report back?