MobDev.TfliteDownloader (mob_dev v0.5.7)

Copy Markdown View Source

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:

  • Androidtensorflow-lite-2.16.1.aar from Maven Central (the last release with a packed .aar; 2.17.0 ships .jar only). Extracted to jni/arm64-v8a/libtensorflowlite_jni.so + headers/tensorflow/lite/c/c_api.h etc.
  • iOSTensorFlowLiteC-2.17.0.tar.gz from dl.google.com (CocoaPods upstream). Contains three xcframeworks (Core, CoreML, Metal) each with ios-arm64 device + ios-arm64_x86_64-simulator slices.

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: hashed URL + cached extraction at ~/.mob/cache/tflite-<version>-<target>/, validated against the expected layout. Reused across projects.

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 locally-fetched tarballs (named exactly as tarball_name/1 returns). Useful when iterating offline or against a custom TFLite build.

Summary

Types

Target slice this downloader supports.

Functions

Android TFLite version pin.

Cached TFLite root directory for target. May not exist if ensure/1 hasn't been called.

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

target()

@type target() :: :android_arm64 | :android_arm32 | :ios_device | :ios_sim

Target slice this downloader supports.

Functions

android_version()

@spec android_version() :: String.t()

Android TFLite version pin.

dir(target)

@spec dir(target()) :: String.t()

Cached TFLite root directory for target. May not exist if ensure/1 hasn't been called.

ensure(target)

@spec ensure(target()) :: {:ok, String.t()} | {:error, term()}

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).

ios_version()

@spec ios_version() :: String.t()

iOS TFLite version pin.

valid_dir?(target, dir)

@spec valid_dir?(target(), String.t()) :: boolean()

Returns true if the cache directory has the expected layout for the given target. Public for tests and NativeBuild probing.