I've created a simple Flet app with Python, and now it's time to build the Python application into an APK file to run on android devices. However, I can't find the .apk file in the build directory.
After watching a few videos explaining how to build an APK using the flet build
command, I noticed a different output structure.
Typically, after running flet build apk
, others have the following structure:
| project_root └─── build └─── apk └─── release.apk
I have a completely different structure (it's quite extensive, so I'll attach a screenshot if needed):
| project_root └─── build └─── flutter | └─── android | └─── app | └─── ... | └─── site-packages └─── arm64-v8a (this is an empty dir)
I couldn't find the .apk file anywhere.
After running the flet build apk
command, this was the output:
Created Flutter bootstrap project from gh:flet-dev/flet-build-template with ref 0.25.1 ✅
Customized app icons and splash images ✅
[22:46:13] Generated app icons ✅
[22:46:18] Generated splash screens ✅
[22:46:50] Running package command
Extra PyPi indexes:
Creating asset directory: C:\Users\username\Desktop\Code\Python\Tests\MyApp\build\flutter\app
Created temp directory: C:\Users\username\AppData\Local\Temp\serious_python_temp2448bdf8
Copying Python app from C:\Users\username\Desktop\Code\Python\Tests\MyApp to a temp directory
Cleanup app
Configured Android/arm64-v8a platform with sitecustomize.py
Installing [-r, C:\Users\username\Desktop\Code\Python\Tests\MyApp\requirements.txt] with pip command to C:\Users\username\Desktop\Code\Python\Tests\MyApp\build\site-packages\arm64-v8a
Downloading Python distributive from https://github.com/indygreg/python-build-standalone/releases/download/20240909/cpython-3.12.6+20240909-x86_64-pc-windows-msvc-shared-install_only_stripped.tar.gz to a build directory
Extracting Python distributive
ERROR: Could not find a version that satisfies the requirement flet-desktop==0.25.1 (from versions: none)
ERROR: No matching distribution found for flet-desktop==0.25.1
Error building Flet app - see the log of failed command above.
[22:46:55] Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.24.5, on Microsoft Windows [Version 10.0.26100.2314], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.0)
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.0)
[!] Android Studio (not installed)
[√] Connected device (2 available)
[√] Network resources
[√] Connected device (2 available)
[√] Network resources
[√] Network resources
! Doctor found issues in 3 categories.
I've installed the Flutter SDK and added it to my system variables, along with the Java SDK.
However, the log shows an error: "Could not find a version that satisfies the requirement flet-desktop==0.25.1." When I run pip install flet-desktop==0.25.1
, it indicates that all requirements are already satisfied.
Okay, so after bashing my head against the wall for several hours, I found the solution that worked for me.
The main problem is that Flet developers changed the structure generated by the flet build
command. If you want to have a similar structure with only two directories, go back to flet==0.24
.
Also, after installing the Flutter SDK, open your terminal and run the command flutter doctor -v
. The problem was that I didn't have all the Flutter requirements to build an app, such as Android Studio not being installed, Android Licenses not being accepted, and Chrome not being installed (I'm quite sure this one is optional, but the others are not). Make sure you have them all with the green tick.
After doing all of that, I encountered a different problem. The flet build
command was working, but no build directories were being created. If that's your case, run the command flet build apk -vv
. It shows the build process in detail, and there I found out I was having some issues with my requirements.txt
file. Fixing that also helped resolve the problem.
Enable Developer Mode in Windows by typing start ms-settings:developers
in the terminal or by going to Settings > System > For developers > Developer Mode
.
Having Windows 10 or later is recommended.
Run the $PSVersionTable
command in the terminal and check if your PSVersion
is 5.0 or later.
These are all the changes I had to make to get things working on Windows. I hope it works for you too.