Stop using error-prone string paths. Get compile-time safety and IDE autocomplete for your Android assets.
Android Assets Journalist is a Gradle plugin that automatically generates type-safe constants for all your Android assets/ files. No more typos, no more guessing paths, no more runtime crashes.
// โ Error-prone string paths
val modelPath = "models/tesorflow_lite_model.tflite" // Oops, typo!
val jsonPath = "configs/app_config.json" // Where is this used? IDE can't find it
// โ Runtime crashes when files are renamed or moved
assets.open("old_path/file.json") // Crash!
// โ No autocomplete - you have to remember every path
assets.open("???") // Good luck remembering// โ
Type-safe, generated constants
val modelPath = AssetFiles.MODELS_TENSORFLOW_LITE_MODEL_TFLITE
val jsonPath = AssetFiles.CONFIGS_APP_CONFIG_JSON
// โ
Refactor-safe rename support
assets.open(AssetFiles.MODELS_TENSORFLOW_LITE_MODEL_TFLITE) // IDE knows this!
// โ
Full IDE autocomplete support
AssetFiles. // Press Ctrl+Space and see all assets- ๐ฎ Games - Managing sprite sheets, audio files, level data, game assets
- ๐ง Machine Learning - TensorFlow Lite models, ONNX files, ML configs
- ๐ WebView Apps - Local HTML, CSS, JavaScript files
- ๐ Document Viewers - PDF templates, custom fonts, document resources
- ๐ฆ Asset-Heavy Apps - Any app with 10+ files in
assets/ - ๐ง Configuration-Heavy Apps - JSON configs, XML schemas, property files
| Feature | Benefit |
|---|---|
| ๐ Compile-time safety | Catch typos at build time, not runtime crashes |
| ๐ค IDE autocomplete | Press Ctrl+Space and see all your assets instantly |
| ๐ Refactoring support | Rename assets safely - IDE updates all references |
| โก Zero runtime overhead | Generated constants, no reflection or runtime cost |
| ๐ฑ AGP 8.x compatible | Works with Android Gradle Plugin 8.8.0+ |
| ๐จ Multiple output formats | XML strings or Kotlin constants |
| โ๏ธ Highly configurable | Prefixes, path transformations, filtering |
// build.gradle.kts (plugins block)
plugins {
id("com.github.utilx.android-assets-journalist") version "1.0.0"
}androidAssetsJournalist {
// Generate Kotlin constants (default: enabled)
kotlinFile {
enabled = true
className = "AssetFiles"
packageName = "com.yourcompany.yourapp"
}
// Or Android string resources
xmlFile {
enabled = false
}
}./gradlew assembleDebugimport com.yourcompany.yourapp.AssetFiles
// Access any asset with type-safe constants
val model = AssetFiles.MODELS_ML_MODEL_TFLITE
val config = AssetFiles.CONFIGS_SETTINGS_JSONGiven these assets:
src/main/assets/
โโโ models/
โ โโโ ml_model.tflite
โโโ configs/
โโโ settings.json
// AssetFiles.kt
package com.github.utilx
object AssetFiles {
const val MODELS_ML_MODEL_TFLITE: String = "models/ml_model.tflite"
const val CONFIGS_SETTINGS_JSON: String = "configs/settings.json"
}<!-- res/values/assets-strings.xml -->
<resources>
<string name="models_ml_model_tflite">models/ml_model.tflite</string>
<string name="configs_settings_json">configs/settings.json</string>
</resources>androidAssetsJournalist {
kotlinFile {
className = "Assets"
packageName = "com.myapp.util"
constNamePrefix = "ASSET_"
constValuePrefix = "file:///android_asset/"
}
}Output:
const val ASSET_MODELS_ML_MODEL_TFLITE: String = "file:///android_asset/models/ml_model.tflite"androidAssetsJournalist {
kotlinFile {
// Replace "dev_" prefix with "prod_" in generated paths
replaceInAssetsPath = [
[match: '^dev_', replaceWith: 'prod_']
]
}
}androidAssetsJournalist {
// XML String Resources
xmlFile {
enabled = false // Enable to generate res/values/*.xml
stringNamePrefix = "prefix_"
}
// Kotlin Constants Object
kotlinFile {
enabled = false
className = "AssetFilesKt"
packageName = "com.github.utilx"
constNamePrefix = "asset_"
constValuePrefix = ""
replaceInAssetsPath = [
[match: '^dev_', replaceWith: 'prod_'],
[match: 'test_', replaceWith: '']
]
}
}- Java: 17 or higher
- Android Gradle Plugin: 8.+ - Check given release notes for compatibility report.
- Gradle: 8.+
- Kotlin: 1.9.0 or higher (for Kotlin DSL)