Skip to content

Gradle Plugin that creates source files with android assets listing

License

Notifications You must be signed in to change notification settings

karczews/android-assets-journalist

Repository files navigation

Android Assets Journalist

N|Solid Build Status codecov Quality Gate Status FOSSA Status License

Android Assets Journalist is gradle plugin that can be used in Android project to generate listing of android asset files in certain library.

Assets listing file can be generated in 3 ways

Android strings xml file

Given project contains following asset files: src/main/assets/testName.testExtension, src/main/assets/subdir/testName.testExtension Plugin can generate xml file in build/generated/assetsjournalist/src/main/res/values/asset-strings.xml as:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <string name="testName_testExtension">testName.testExtension</string>
  <string name="subdir_testName_testExtension">subDir/testName.testExtension</string>
</resources>

Java source class

Given project contains following asset files: src/main/assets/testName.testExtension, src/main/assets/subdir/testName.testExtension Plugin can generate java file in /build/generated/assetsjournalist/src/main/java/com/github/utilx/AssetFiles.java

public final class AssetFiles {
  public static final String ASSET_TESTNAME_TESTEXTENSION = "testName.testExtension";
  public static final String ASSET_SUBDIR_TESTNAME_TESTEXTENSION = "subDir/testName.testExtension";
}

Kotlin source class

Given project contains following asset files: src/main/assets/testName.testExtension, src/main/assets/subdir/testName.testExtension Plugin generate kotlin file in /build/generated/assetsjournalist/src/main/kotlin/com/github/utilx/AssetFiles.kt

object AssetFiles {
    const val ASSET_TESTNAME_TESTEXTENSION = "testName.testExtension"
    const val ASSET_SUBDIR_TESTNAME_TESTEXTENSION = "subDir/testName.testExtension"
}

How to apply plugin

gradle-plugin-repository

How to configure plugin

Once plugin is applied, in order to configure plugin use androidAssetsJournalist extension. Following configuration presents all configuration options with default values or example values. Default values will be applied if not specified by integrator.

androidAssetsJournalist {

    xmlFile {
        // enables xml string resource file generation
        enabled = false
        // prefix for each string name
        stringNamePrefix = "prefix_"
    }

    javaFile {
        // enable java source file generation
        enabled = true
        // class name to generate
        className = "AssetFiles"
        // package name for generated class
        packageName = "com.github.utilx"
        // prefix for each constant
        constNamePrefix = "asset_"
        // prefix to applt for each path, empty by default
        constValuePrefix = ""
        // regexp for replacing matching part of asset path, none by default
        replaceInAssetsPath = [ ]
    }

    kotlinFile {
        // enable kotlin source file generation
        enabled = false
        // class name to generate
        className = "AssetFilesKt"
        // package name for generated class
        packageName = "com.github.utilx"
        // prefix for each constant
        constNamePrefix = "asset_"
        // prefix to apply to each asset path, example:
        constValuePrefix = "assetFile://"
        // regexp for replacing matching part of asset path with provided replacement string
        replaceInAssetsPath = [
                // example1: replace each "ab" at the start of each path with "zx"
                [match: '^ab', replaceWith: 'zx'],
                // example2: replace each "da" or "db" with "cd"
                [match: 'd[ab]', replaceWith: 'cd']
            ]
        
    }
}

What's new:

0.11.0 - Added library/application variant support

License

FOSSA Status

About

Gradle Plugin that creates source files with android assets listing

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •