Skip to content

build(android): consume serious_python native-mmap packaging + --android-extract-packages#6595

Merged
FeodorFitsner merged 3 commits into
dart-bridgefrom
android-native-mmap
Jun 17, 2026
Merged

build(android): consume serious_python native-mmap packaging + --android-extract-packages#6595
FeodorFitsner merged 3 commits into
dart-bridgefrom
android-native-mmap

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes flet build apk/aab consume serious_python's new Android packaging (see flet-dev/serious-python#210): native modules memory-mapped from the APK, pure Python in stored zipimport zips, no useLegacyPackaging.

  • Build template — pubspec references the serious_python android-native-mmap branch; the app build.gradle.kts drops the now-stale packaging { jniLibs { useLegacyPackaging = true; keepDebugSymbols += … } } block (modern packaging applies by default at minSdk 23+).
  • --android-extract-packages CLI flag + [tool.flet.android].extract_packages (with a [tool.flet].extract_packages fallback) to ship "path-hungry" packages extracted to disk. A built-in default set (certifi) is always extracted; the user list is merged on top. The resolved list is exported as SERIOUS_PYTHON_ANDROID_EXTRACT_PACKAGES on the flutter build env, where the serious_python Gradle split consumes it.
  • Docs — new "Android extract packages" publish-docs section (resolution order + CLI/pyproject example) and a CHANGELOG entry.

flet itself is already zip-safe: icons load via importlib.resources; version.py short-circuits __file__/git/.fvmrc on mobile — no changes needed.

Verification

Built a real Flet UI app and ran it on an arm64 emulator via both flet build apk and flet build aab (bundletool split install). All green on both paths:

  • numpy extension mmap'd from the APK / split_config.arm64_v8a.apk (83 native .so in the ABI config split, zero in master)
  • certifi extracted to …/files/flet/py/extract/certifi/cacert.pem
  • flet icons.json read from the stored sitepackages.zip via importlib.resources
  • flet.version resolved; UI launched (ft.Icon rendered)

Note for release

The template currently pins serious_python to the android-native-mmap test branch — flip to the merged dart-bridge (or a tagged serious_python release) before shipping, and carry the same Gradle/pubspec edits into the released flet-build-template.zip.

Depends on flet-dev/serious-python#210.

Summary by Sourcery

Adopt serious_python’s new Android native-mmap packaging in the Flet Android build template and add configuration for extracting path-dependent Python packages on Android builds.

New Features:

  • Add an --android-extract-packages CLI flag and corresponding pyproject settings to specify Python packages that must be shipped extracted to disk on Android.
  • Export the resolved Android extract-packages list to Flutter builds via the SERIOUS_PYTHON_ANDROID_EXTRACT_PACKAGES environment variable.

Enhancements:

  • Update the Android build template to rely on modern native library packaging, removing legacy jniLibs packaging configuration.
  • Point the template serious_python dependency to the android-native-mmap branch that supports native-mmap Android packaging.

Documentation:

  • Document Android extract-packages behavior, resolution order, and configuration examples in the publish documentation.
  • Note the new Android packaging behavior and extract-packages option in the changelog.

Chores:

  • Whitelist the certifi package name in the typos configuration as it is now part of the default Android extract-packages list.

…t-packages option

- Build template: point serious_python git ref at android-native-mmap; drop the stale
  packaging{jniLibs{useLegacyPackaging=true; keepDebugSymbols}} block from the Android
  app build.gradle.kts (native modules now load mmap'd from the APK; modern packaging at
  minSdk 23+ is all that's needed).
- flet-cli: add --android-extract-packages CLI flag + [tool.flet.android].extract_packages
  (cross-platform [tool.flet].extract_packages fallback), a built-in
  ANDROID_DEFAULT_EXTRACT_PACKAGES set (certifi), merged and exported as
  SERIOUS_PYTHON_ANDROID_EXTRACT_PACKAGES for the serious_python package step. Mirrors the
  existing --source-packages -> SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS flow.
The serious_python_android Gradle split (which partitions site-packages into
the stored sitepackages.zip vs the extracted extract.zip) runs during
`flutter build`, not the `serious_python package` step. Set
SERIOUS_PYTHON_ANDROID_EXTRACT_PACKAGES on build_env (resolved once into
self.android_extract_packages) so the default set (certifi) and user list
actually reach the split — previously it was set on the package step's env
and silently ignored, leaving extract.zip empty.

Add the "Android extract packages" publish-docs section (resolution order,
CLI + pyproject example), a CHANGELOG entry, and allowlist `certifi` in typos.

Verified end-to-end on an arm64 emulator via both `flet build apk` and
`flet build aab` (bundletool split install): numpy mmap'd from the APK,
certifi extracted to disk, flet icons.json read from the stored zip,
flet.version resolved, app launched.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 17, 2026

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6693b32
Status: ✅  Deploy successful!
Preview URL: https://5ceac8c8.flet-website-v2.pages.dev
Branch Preview URL: https://android-native-mmap.flet-website-v2.pages.dev

View logs

certifi reads cacert.pem via importlib.resources.as_file(), which extracts it
to a temp file on demand, so certifi.where() works from inside the stored
sitepackages.zip (verified: imported via zipimport, where() returns a valid
234KB cacert.pem). It does not need to ship extracted.

Make ANDROID_DEFAULT_EXTRACT_PACKAGES empty — the common data-bundling
packages use importlib.resources (zip-safe). The --android-extract-packages /
[tool.flet.android].extract_packages mechanism stays for genuinely path-hungry
packages (those reading data via __file__ / pkg_resources). Update docs and
CHANGELOG accordingly.
@FeodorFitsner FeodorFitsner merged commit 17ad995 into dart-bridge Jun 17, 2026
98 of 143 checks passed
@FeodorFitsner FeodorFitsner deleted the android-native-mmap branch June 17, 2026 18:54
@FeodorFitsner FeodorFitsner restored the android-native-mmap branch June 17, 2026 18:55
@FeodorFitsner FeodorFitsner deleted the android-native-mmap branch June 17, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant