ModuleNotFoundError when installing an update from an older version of the app on Android
As the title suggests, when I add a dependency under dependencies in pyproject.toml, if I install an installation package from an old version on Android to update to the new version, I will get a ModuleNotFoundError when importing the new module. This issue does not occur if you uninstall the old version before updating.
How to reproduce:
-
Modify
pyproject.tomlOld
pyproject.toml:dependencies = [ ... "requests" ]New:
dependencies = [ ... "cffi", "requests" ] -
Build command:
flet build apk -vflet0.28.3requires-python:>=3.13.5 -
Update the app from the older version using the apk. Android:
16.0 ("Baklava")|x86_64
Expected:
The app should properly import the newly added dependencies after updating from the old version to start properly.
Hello @Creeper19472 The error you're encountering is likely because of incompatible data used by the latest version which is meant for the previous one. The only workaround so far is to Clear App Data of that App in order for the latest version to create its own data.
Thanks.
@HappyCoder256 Is there no way to let the software handle the data wipe job on its own?
I think i should tag @ndonkoHenri and @FeodorFitsner to resolve this issue since it's functionality is embedded in the main flutter package ### Flet
Thanks for the detailed report, and apologies for the very slow follow-up.
This was a real bug. In the serious_python version that flet 0.28.3 shipped, the Android site-packages archive was unpacked on first launch and then never refreshed — the extraction had no invalidation key at all, so <appSupport>/flet/python_site_packages was effectively write-once for the life of the install. Your app's own code was hash-checked and did update, which is exactly why you saw the new code run while a newly added dependency was missing, and why uninstalling or clearing app data was the only thing that helped.
It's since been fixed. An invalidation key was added for the extracted payload, and as of serious_python 4.3.4 that key includes the package's lastUpdateTime, so it changes on every install — including a same-version update-install like yours. That shipped in flet 0.86.2; current releases are well past it.
I've now re-run your exact scenario on an Android 14 emulator against current flet, with the app version deliberately left unchanged between the two builds so that only lastUpdateTime could differ:
v1 (dependencies = ["flet"]) -> cowsay MISSING (ModuleNotFoundError)
adb install -r v2.apk # no uninstall, same versionName+versionCode
v2 (dependencies = ["flet", "cowsay"]) -> cowsay OK
.key app:1.0.0+1+1788479167095 -> app:1.0.0+1+1788479456195
sitepackages.zip 5,576,574 bytes -> 5,684,972 bytes
The payload is genuinely re-extracted on an in-place update, and a plain relaunch still hits the cache.
Closing this ticket as fixed. Let know if you face any other issues.