Overview
Play Asset Delivery (PAD) allows you to separate large model files from your base APK into asset packs that are installed alongside your app. This keeps your base APK small while ensuring models are available at runtime.Benefits of using PAD
- Smaller base APK: Keep your main APK under size limits for faster downloads
- On-demand or install-time delivery: Models can be delivered when the app is installed or requested on-demand
- Organized model management: Separate model files from app code
- Better user experience: Users don’t wait for large model downloads on first launch
PAD is an Android-only feature. On iOS, you can use folder references in Xcode to bundle models, or implement on-demand downloads using the Download Manager API.
How it works
- Create an asset pack module (e.g.,
sherpa_models) in your Android project - Place model files in the asset pack’s assets directory
- Configure your app to reference the asset pack
- At runtime, use
getAssetPackPath()to get the path to extracted models - List and load models from the PAD directory
Setup
Create the asset pack module
Create a new Gradle module for your asset pack in your Android project:Create
android/sherpa_models/build.gradle:Use
deliveryType = "install-time" to ensure models are available immediately. For optional models, use "on-demand".Add models to the asset pack
Place your model folders in the asset pack’s assets directory:Each subfolder under
models/ represents one complete model.Reference the asset pack in your app
In your app’s Also add the asset pack module to
build.gradle, add the asset pack reference:settings.gradle:Runtime usage
Once your app is installed with the asset pack, use these APIs to access models:Get the asset pack path
getAssetPackPath() returns null if the app was not installed with the asset pack, or on iOS (where PAD is not supported).List models in the asset pack
Initialize with PAD models
Complete example
Here’s a full example of PAD setup in a React Native component:API reference for PAD
| API | Description |
|---|---|
getAssetPackPath(packName) | Returns the filesystem path to the asset pack’s content, or null if not available. Android only. |
listModelsAtPath(path, recursive?) | Lists model folders under the given path. Use this for PAD paths, not listAssetModels(). |
fileModelPath(filePath) | Returns { type: 'file', path: filePath } for use with initialization. |
Use
listAssetModels() for bundled assets in the main APK, and listModelsAtPath() for PAD or downloaded models.Comparison: Bundled vs PAD
Bundled assets (main APK)
- Models are in
android/app/src/main/assets/models/ - Accessed with
{ type: 'asset', path: 'models/folder-name' } - Listed with
listAssetModels() - Increases base APK size
- Always available at runtime
Play Asset Delivery
- Models are in a separate asset pack module
- Accessed with
{ type: 'file', path: fullPath }wherefullPathcomes fromgetAssetPackPath() - Listed with
listModelsAtPath(padPath) - Base APK stays small
- Requires AAB build and Play Store (or bundletool for local testing)
- May not be available if the app wasn’t installed with the pack
Debugging with PAD
Local testing
To test PAD locally without uploading to Play Store:- Install bundletool: Download from GitHub releases
- Build and install with PAD:
- Start Metro and connect:
Release testing
- Build a release AAB:
./gradlew bundleRelease - Upload to Play Console (internal testing track)
- Install on device and verify
getAssetPackPath()returns a valid path
Troubleshooting
getAssetPackPath() returns null
Cause: The app was not installed from a bundle that includes the asset pack.
Solutions:
- Ensure you built an AAB (not just APK)
- For local testing, use bundletool to extract and install the asset pack
- Verify
assetPacksis correctly set inbuild.gradle - Check that the asset pack module is included in
settings.gradle
Models list is empty
Cause: The path passed tolistModelsAtPath() doesn’t contain model folders.
Solutions:
- Verify the PAD path with
console.log(padPath) - Check that models are in
android/sherpa_models/src/main/assets/models/ - Ensure each model folder contains required files (e.g.,
model.onnx,tokens.txt) - Rebuild the AAB after adding models
”Model directory does not exist”
Cause: The model path is incorrect or the asset pack wasn’t extracted. Solutions:- Ensure you’re using
{ type: 'file', path: fullPath }, not{ type: 'asset', ... } - Verify the full path includes the model folder name:
${padPath}/models/folder-name - Check that
getAssetPackPath()returned a non-null value
Bundletool not found
Cause:bundletool is not in your PATH.
Solutions:
- Download bundletool JAR from GitHub
- Add to PATH, or create an alias:
alias bundletool='java -jar /path/to/bundletool.jar' - Or pass the path in Gradle:
./gradlew installDebugWithPad -Pbundletool=/path/to/bundletool.jar
Best practices
Use install-time delivery for critical models
Set
deliveryType = "install-time" for models that are essential at first launch. Use "on-demand" for optional or large models that can be downloaded later.Provide a fallback path
Always check if This ensures your app works even if the asset pack isn’t available.
getAssetPackPath() returns null and provide a fallback:Organize models by type
Keep all models in a consistent structure:Use
recursive: true with listModelsAtPath() to scan subdirectories.See also
- Model Setup Guide - Complete guide to model management
- Download Manager - Download models at runtime
- Bundled Assets - Alternative to PAD for smaller models