vgo
vgo optimizes vector graphics through a format-agnostic approach by leveraging vgo-core's intermediate representation. It can convert between common vector formats, including SVG, Android Vector Drawables, and Jetpack Compose ImageVector and optimize them to boot.
Homebrew
brew install jzbrooks/repo/vgo
Manually
Download the distribution from the release page and ensure it has execute permission. On macOS & Linux run chmod u+x vgo.
vgo requires Java 17.
Gradle Plugin
The plugin aims to be fast and small by leveraging (for the entire tool) the JVM your Gradle build is already using.
The shrinkVectorGraphic task is added to your project on plugin application.
The checkVectorGraphic task is also added, a verification counterpart that fails the build if any
vector graphic is not fully shrunk (without modifying any files)
To incorporate the plugin in your build, configure maven central plugin resolution:
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
Then, in the relevant project, add the plugin.
[!NOTE] You must have the android tools sdk on your build classpath if you are converting SVGs to vector drawables. This is typically done by applying the Android Gradle Plugin. You must have the kotlin compiler on your build classpath if you are using the
ImageVectorformat. This is typically done by applying the Kotlin Gradle Plugin.
plugins {
id 'com.jzbrooks.vgo'
}
// Default configuration shown
vgo {
inputs = fileTree(projectDir) {
include '**/res/drawable*/*.xml'
}
outputs = inputs // omit to optimize files in place
showStatistics = true
format = OutputFormat.UNCHANGED
noOptimization = false
indent = 0
}
[!TIP] For Android projects a non-zero indent is better for readability and provides no apk size impact after AAPT processing.
Command Line Interface
> vgo [options] [file/directory]
Options:
-h --help print this message
-o --output file or directory, if not provided the input will be overwritten
-s --stats print statistics on processed files to standard out
-v --version print the version number
--indent [value] write files with value columns of indentation
--format [value] output format (svg, vd, iv)
--no-optimiation skip graphic optimization
--check verify inputs are fully shrunk without writing; prints files that would change and exits non-zero
--print-ir[=MODE] print IR tree and exit without writing (auto [default], color, plain; use = to pass mode)
java -jar vgofor Windows
Examples
CLI
# Optimize files specified from standard in
> find ./**/ic_*.xml | vgo
# Optimize vector.xml and overwrite its contents
> vgo vector.xml
# Optimize vector.xml and write the result into new_vector.xml
> vgo vector.xml -o new_vector.xml
# Optimize multiple input sources write results to the
> vgo vector.xml -o new_vector.xml ./assets -o ./new_assets
# Fail (non-zero exit) if any vector is not fully shrunk — useful in CI
> vgo --check ./assets
Gradle Plugin
// Optimize and convert svgs to vector drawables at build time
vgo {
format = OutputFormat.VECTOR_DRAWABLE
inputs = fileTree(projectDir) {
include("icons/**/*.svg")
}
val drawableDir = layout.projectDirectory.dir("src/main/res/drawable")
outputs.setFrom(
inputs.elements.map { svgs ->
svgs.map { svg -> drawableDir.file("${svg.asFile.nameWithoutExtension}.xml").asFile }
}
)
}
tasks.named("processDebugResources") {
dependsOn("shrinkVectorGraphic")
}
Build instructions
This project uses the Gradle build system.
To build the binary: ./gradlew binary
To run the tests: ./gradlew check
To see all available tasks: ./gradlew tasks
