# `MobDev.TfliteDownloader`
[🔗](https://github.com/genericjam/mob_dev/blob/master/lib/mob_dev/tflite_downloader.ex#L1)

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.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.
* **iOS** — `TensorFlowLiteC-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.

# `target`

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

Target slice this downloader supports.

# `android_version`

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

Android TFLite version pin.

# `dir`

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

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

# `ensure`

```elixir
@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`

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

iOS TFLite version pin.

# `valid_dir?`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
