Skip to content

karczews/android-assets-journalist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

116 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Android Assets Journalist ๐Ÿ—‚๏ธ

Gradle Plugin CI codecov FOSSA Status License

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.

The Problem ๐Ÿ˜ซ

// โŒ 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

The Solution โœจ

// โœ… 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

Perfect For ๐ŸŽฏ

  • ๐ŸŽฎ 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

Why Choose Android Assets Journalist? ๐Ÿ†

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

Quick Start ๐Ÿš€

1. Apply the plugin

// build.gradle.kts (plugins block)
plugins {
    id("com.github.utilx.android-assets-journalist") version "1.0.0"
}

2. Configure (optional)

androidAssetsJournalist {
    // Generate Kotlin constants (default: enabled)
    kotlinFile {
        enabled = true
        className = "AssetFiles"
        packageName = "com.yourcompany.yourapp"
    }
    
    // Or Android string resources
    xmlFile {
        enabled = false
    }
}

3. Build and use

./gradlew assembleDebug
import com.yourcompany.yourapp.AssetFiles

// Access any asset with type-safe constants
val model = AssetFiles.MODELS_ML_MODEL_TFLITE
val config = AssetFiles.CONFIGS_SETTINGS_JSON

Generated Output Examples ๐Ÿ“„

Given these assets:

src/main/assets/
โ”œโ”€โ”€ models/
โ”‚   โ””โ”€โ”€ ml_model.tflite
โ””โ”€โ”€ configs/
    โ””โ”€โ”€ settings.json

Kotlin Output

// 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"
}

XML Output

<!-- 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>

Advanced Configuration โš™๏ธ

Custom Prefixes

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"

Path Transformations

androidAssetsJournalist {
    kotlinFile {
        // Replace "dev_" prefix with "prod_" in generated paths
        replaceInAssetsPath = [
            [match: '^dev_', replaceWith: 'prod_']
        ]
    }
}

Configuration Reference ๐Ÿ“–

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: '']
        ]
    }
}

Requirements โœ…

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

License

FOSSA Status

About

Gradle Plugin for compile-time safe assets

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors