Downloads and caches pre-built TensorFlow Lite native libraries for Android and iOS so Mob apps can ship the TFLite Nx backend without building TFLite from source (Bazel).
Two upstream sources:
- Android —
tensorflow-lite-2.16.1.aarfrom Maven Central (the last release with a packed.aar; 2.17.0 ships.jaronly). Extracted tojni/arm64-v8a/libtensorflowlite_jni.so+headers/tensorflow/lite/c/c_api.hetc. - iOS —
TensorFlowLiteC-2.17.0.tar.gzfromdl.google.com(CocoaPods upstream). Contains three xcframeworks (Core, CoreML, Metal) each withios-arm64device +ios-arm64_x86_64-simulatorslices.
The C API is binary-compatible between these versions — TFLite's
c_api.h surface has been stable since 2.13. Different version pins
per platform reflect upstream packaging differences, not API drift.
Mirrors the MobDev.MLXDownloader pattern: pinned URL + cached
extraction at ~/.mob/cache/tflite-<version>-<target>/, validated
against the expected layout. Reused across projects. The AAR, the iOS
tarball and the two headers patched into the Android tree are checked
against their SHA-256 pins in MobDev.Download.Pins (the downloaded
AAR/tarball again on every reuse), and an extracted cache is reused
only if it came from the pinned archive.
Used by MobDev.NativeBuild when the project enables TFLite via
mix mob.enable tflite. The build template sources TFLITE_DIR from
dir/1 and links the tflite_nif.c NIF against the headers and
framework / .so it provides.
Local-build override
Set MOB_TFLITE_LOCAL_TARBALL_DIR=/path/to/dir to bypass the upstream
download and use tensorflow-lite-<android_version>.aar /
TensorFlowLiteC-<ios_version>.tar.gz from that directory. Useful when
iterating offline or against a custom TFLite build. A local archive is
your own choice, so it is not held to the pin; its hash is recorded
instead, and the cache it produced is replaced once the override is unset.
Summary
Functions
Android TFLite version pin.
Cached TFLite root directory for target. May not exist if ensure/1
hasn't been called.
Every URL this downloader can request.
Ensure the TFLite bundle for target is cached and extracted.
iOS TFLite version pin.
Returns true if the cache directory has the expected layout for the
given target. Public for tests and NativeBuild probing.
Types
Functions
@spec android_version() :: String.t()
Android TFLite version pin.
Cached TFLite root directory for target. May not exist if ensure/1
hasn't been called.
@spec download_urls() :: [String.t()]
Every URL this downloader can request.
Ensure the TFLite bundle for target is cached and extracted.
Returns {:ok, path} where path is the unpacked root containing the
expected layout (see valid_dir?/2).
@spec ios_version() :: String.t()
iOS TFLite version pin.
Returns true if the cache directory has the expected layout for the
given target. Public for tests and NativeBuild probing.