freshcrate
Skin:/
Home > Databases > svg-to-compose

svg-to-compose

Convert SVG and Android Vector Drawables (XML) into Jetpack Compose ImageVector code. CLI, Gradle plugin, and online playground. Kotlin Multiplatform supported.

Why this rank:Strong adoptionRelease freshnessHealthy release cadence

Description

Convert SVG and Android Vector Drawables (XML) into Jetpack Compose ImageVector code. CLI, Gradle plugin, and online playground. Kotlin Multiplatform supported.

README

S2C - SVG to Compose

SVG to Compose

Built with KMP SVG to Compose Latest version SVG to Compose Gradle Plugin Latest version LICENSE

A suite of tools to convert SVG or Android Vector Drawable (AVD/XML) files into Android Jetpack Compose Icons. This project provides:

  • A command-line tool for manual conversion.
  • A Gradle plugin for automating the conversion within your build process.

Website: svgtocompose.com


For more detailed information on each tool, configurations, and features, please refer to the full documentation:


Table of Contents

Why?

With the introduction of Jetpack Compose, Android developers can leverage the full power of Kotlin to build UI components, moving away from traditional XML layouts. However, integrating vector assets like icons often still relies on using Android Vector Drawables (AVD/XML) resources.

This project aims to streamline the integration of vector assets into Compose applications by providing tools that convert SVG or AVD files directly into Compose ImageVector objects, following the same approach used for Google's Material Icons.

Key Advantages:

  • Custom Parsing Algorithm: The project employs its own parsing algorithm, written on Kotlin Multiplatform, specifically designed to handle complex vector graphics that are not fully supported by the standard com.android.tools:sdk-common library.
  • Addresses Missing Features: By addressing missing features in the default SDK tools, the algorithm can parse and convert complex SVGs and AVGs that other tools might fail to process correctly.
  • Supports Complex Vectors: Capable of handling intricate vector graphics, ensuring that even detailed icons are accurately converted.
  • Optimization via Trusted Tools: The optimization of SVGs is performed using external, well-known dependencies like SVGO and Avocado, ensuring efficient and clean generated code without reinventing the wheel.

Platform Support

Command-line Tool

Platform Command-line Tool
macOS Arm64 ✅
macOS x64 ✅
Linux x64 ✅
Windows (mingwX64) ✅
Windows (WSL) ✅

Gradle Plugin

Platform Gradle Plugin
Android ✅
Kotlin Multiplatform ✅

Available Tools

Command-line Tool

A CLI tool for manually converting SVG or AVD files into Jetpack Compose ImageVector objects. It supports optimization of SVGs and provides various options for customization.

Ideal for CI integration as no additional dependencies are required (not even Java) other than the CLI tool's script and, if you wish, the optimization tools.

Full documentation for the Command-line Tool can be found here.

Gradle Plugin

A Gradle plugin that automates the conversion process within your build system, ideal for projects with a large number of icons or for ensuring consistency and saving development time.

Full documentation for the Gradle Plugin can be found here.

Getting Started

Command-line Tool Installation

Homebrew (macOS / Linux)

brew tap dev-tonholo/svg-to-compose
brew install s2c

Scoop (Windows)

scoop bucket add svg-to-compose https://github.com/dev-tonholo/scoop-svg-to-compose
scoop install s2c

Manual Installation

The CLI tool relies on Kotlin Native to parse the SVG/AVD files. You can install it by:

  1. Downloading the s2c script from this repository and saving it in your preferred folder, or
  2. Cloning the project.

The script will handle downloading or building the native binaries.

After downloading the script or cloning the project:

  1. Give execution permission to the script:

    chmod +xw s2c
  2. Optionally, add the script to your PATH to run it from anywhere:

    export PATH=<s2c path>:$PATH

    Replace <s2c path> with the folder's path where you stored the script.

External Dependencies

Note

This is optional. If you don't want to use external dependencies, make sure to disable optimization via --optimize false when using the CLI tool or by calling the optimize(enabled = false) when using the Gradle Plugin.

Important

By default, Optimization is enabled by default on both CLI tool and Gradle Plugin.

For SVG optimization, this script relies on:

  • SVGO: Optimizes SVG files by reducing paths.

    npm -g install svgo
  • Avocado: Optimizes Android VectorDrawable and AnimatedVectorDrawable XML files.

    npm -g install avocado

Gradle Plugin Installation

The SVG/XML to Compose Gradle Plugin is available on Maven Central. It simplifies the process of converting SVG and Android Vector Drawable (AVG/XML) files into Jetpack Compose ImageVector properties, automating the integration of vector assets into your Compose projects, ensuring a more efficient and error-free workflow.

Applying the plugin

Add the plugin to your module's build.gradle.kts file:

plugins {
    id("dev.tonholo.s2c") version "<latest-version>"
}

Ensure that Maven Central is included in your plugin repositories. If not, add the following to your settings.gradle.kts or build.gradle.kts:

pluginManagement {
    repositories {
        mavenCentral()
        gradlePluginPortal()
    }
}

Configuring .gitignore

Both the CLI tool and the Gradle plugin create a hidden folder to handle the conversion of the vectors without modifying the original file.

To avoid VCS noise, make sure you add the following to your .gitignore which is located in the root folder of your project or the folder you are using the tool in:

.s2c

The algorithm will delete all the contents of the .s2c folder after parsing, but leave it empty. If you delete the folder, it will be recreated on the next run.

Usage

Using the Command-line Tool

Note

For detailed usage instructions and options, please refer to the Command-line Tool Documentation.

To see all available options, run:

s2c --help

Example Commands

  • Convert an SVG to a Compose Icon:

    s2c -o OutputIconFile.kt \
        -p your.app.package.icon \
        -t your.app.package.theme.YourAppComposeTheme \
        input.svg
  • Convert an Android Vector Drawable to a Compose Icon:

    s2c -o OutputIconFile.kt \
        -p your.app.package.icon \
        -t your.app.package.theme.YourAppComposeTheme \
        input.xml
  • Convert all SVGs and AVGs within a directory to Compose Icons:

    s2c -o /my/desired/directory \
        -p your.app.package.icon \
        -t your.app.package.theme.YourAppComposeTheme \
        /my/svg/or/xml/directory

Using the Gradle Plugin

Note

For a complete list of configuration options and advanced usage, please refer to the Gradle Plugin Documentation.

After applying the plugin, configure it in your build.gradle.kts file using the svgToCompose extension. This extension allows you to specify how the SVG/AVG files should be processed and converted.

Basic Configuration Example

svgToCompose {
    processor {
        val projectIcons by creating {
            from(layout.projectDirectory.dir("src/main/resources/icons"))
            destinationPackage("com.example.app.ui.icons")
            icons {
                theme("com.example.app.ui.theme.AppTheme")
            }
            // Additional configurations...
        }
    }
}

Result Examples

Simple SVG File

Without Optimization

Command:

s2c -o <app path>/app/src/main/java/dev/tonholo/composeicons/ui/icon/ShieldSolid.kt \
    -p dev.tonholo.composeicons.ui.icon \
    --theme dev.tonholo.composeicons.ui.theme.ComposeIconsTheme \
    -opt=false \
    <parent-path>/shield-halved-solid.svg

Input file: shield-halved-solid.svg

Output file: ShieldSolid.nonoptimized.kt

With Optimization

Command:

s2c -o <app path>/app/src/main/java/dev/tonholo/composeicons/ui/icon/ShieldSolid.kt \
    -p dev.tonholo.composeicons.ui.icon \
    --theme dev.tonholo.composeicons.ui.theme.ComposeIconsTheme \
    -opt=true \
    <parent-path>/shield-halved-solid.svg

Input file: shield-halved-solid.svg

Output file: ShieldSolid.svg.optimized.kt

Complex SVG File

Without Optimization

Command:

s2c -o <app path>/app/src/main/java/dev/tonholo/composeicons/ui/icon/Illustration.kt \
    -p dev.tonholo.composeicons.ui.icon \
    --theme dev.tonholo.composeicons.ui.theme.ComposeIconsTheme \
    -opt=false \
    <parent-path>/illustration.svg

Input file: illustration.svg

Output file: Illustration.svg.nonoptimized.kt

With Optimization

Command:

s2c -o <app path>/app/src/main/java/dev/tonholo/composeicons/ui/icon/Illustration.kt \
    -p dev.tonholo.composeicons.ui.icon \
    --theme dev.tonholo.composeicons.ui.theme.ComposeIconsTheme \
    -opt=true \
    <parent-path>/illustration.svg

Input file: illustration.svg

Output file: Illustration.svg.optimized.kt

Contributing & Community

Contributions are welcome! Please read the CONTRIBUTING.md for setup instructions, coding standards, branching and PR guidelines, and the PR checklist. By participating in this project, you agree to abide by our Code of Conduct.

Have an idea or found a bug? Open an issue: https://github.com/rafaeltonholo/svg-to-compose/issues/new/choose

License

This software is released under the terms of the MIT License.

Release History

VersionChangesUrgencyDate
2.2.1# What's Changed ## Bug Fixes - **Radial gradient `href` resolution** - Fixed `<radialGradient>` elements that referenced another gradient via `href` or `xlink:href` reading color stops from their own empty child list, producing invisible gradients. The resolver now follows the reference chain, merges inherited attributes, supports both SVG2 plain `href` and legacy `xlink:href`, and detects circular references with a clear error instead of `StackOverflowError`. ([#341](https://github.com/rHigh5/7/2026
2.2.0# What's Changed ## Highlights **Gradle Plugin Parallelism** - The Gradle plugin now uses the Gradle Worker API for parallel SVG/XML icon processing, significantly improving build times for projects with many icons. ([#181](https://github.com/rafaeltonholo/svg-to-compose/pull/181)) **AGP 9 Support** - The Gradle plugin is now compatible with Android Gradle Plugin 9. ([#212](https://github.com/rafaeltonholo/svg-to-compose/pull/212)) **New Website with Live Playground** - A brand-new pHigh4/3/2026
2.1.3## What's Changed ### Features * feat(gradle-plugin): implement Gradle Worker API for parallel SVG/XML icon processing by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/181 ### Fixes * Fix: prevent style attribute to be empty after split by @Godox in https://github.com/rafaeltonholo/svg-to-compose/pull/162 * Fix temp files on Windows by @walterbrebels in https://github.com/rafaeltonholo/svg-to-compose/pull/199 ### Chores * Update project dependencies ## New Low3/8/2026
2.1.2## What's Changed ### Features * Add support to org.gradle.configuration-cache by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/156 ### Fixes * Fix `IllegalArgumentException` when the external dependency is not installed ### Chores * Update project dependencies **Full Changelog**: https://github.com/rafaeltonholo/svg-to-compose/compare/2.1.1...2.1.2Low6/28/2025
2.1.1## What's Changed * Fix wrong rounding with double/float values on x/y by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/130 **Full Changelog**: https://github.com/rafaeltonholo/svg-to-compose/compare/2.1.0...2.1.1Low3/6/2025
2.1.0## What's Changed ### Features * Add support for `<style>` tags by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/99 ### Fixes * Use parsers transient instances instead of singleton by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/111 * Fix tokenizer not properly handling decimals value and improving token parsing by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/123 ### Chores * Move rules computation to SvgRootNodeLow2/17/2025
2.0.1## What's Changed ### Fixes * Fix not considering `<mask>` with non-`<path>` elements and other improvements by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/102 ### Chores * update dependency gradle to v8.11.1 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/91 * update androidx.lifecycle to v2.8.4 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/89 * update dependency com.github.gmazzo.buildconfig:plugin to v5.5.1 by @renLow12/18/2024
2.0.0# Introducing `svg-to-compose` Gradle Plugin This release builds upon the `svg-to-compose` CLI tool code, turning it into a library, where you can use it via script as you are used to, or include it into your project, as a KMP library that parsers and generates code for you. This release sets a big milestone in this project, evolving the project from only a KMP CLI tool to a KMP library, with a native CLI, and a Gradle Plugin. The new `svg-to-compose-gradle-plugin` project was designed Low11/26/2024
v1.3.3## What's Changed * Fixes for Relative Coordinates, and SVG Rect Node Improvements by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/64 * Dependencies upgrades **Full Changelog**: https://github.com/rafaeltonholo/svg-to-compose/compare/v1.3.2...v1.3.3Low9/8/2024
v1.3.2## What's Changed * chore(deps): update dependency com.android.application to v8.4.2 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/46 * fix(deps): update dependency androidx.lifecycle:lifecycle-runtime-ktx to v2.8.2 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/47 * fix(deps): update dependency androidx.compose:compose-bom to v2024.06.00 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/48 * fix(deps): update dependency androidLow8/17/2024
v1.3.1## What's Changed * Bugfix: Add default fill color when neither fillColor or stroke are present by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/45 **Full Changelog**: https://github.com/rafaeltonholo/svg-to-compose/compare/v1.3.0...v1.3.1Low6/10/2024
v1.3.0# What's Changed Adding support for Gradient and other improvements by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/32, closing issue #5. Thanks @t-regbs for the report ## Features - **SVG** - Add support for `use` node - Parse clip path child in a group to as `clip path` data - Apply transform attribute to generated paths - Add support for `polyline` element - Add support for `polygon` element - Add support for `ellipse` element - **Icons** Low6/7/2024
v1.2.0## What's Changed ### Chores - Upgrade the Kotlin version to 2.0.0 by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/41 - Renamed shared module to a more meaningful name by @rafaeltonholo in https://github.com/rafaeltonholo/svg-to-compose/pull/41 ### Dependencies * Update dependency androidx.compose:compose-bom to v2024.04.01 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/26 * Update dependency androidx.activity:activity-compose to v1.9.0 by Low6/4/2024
v1.1.1## What's Changed ### Fixes * ComposeProperty not considering lowercase input value fixing https://github.com/rafaeltonholo/svg-to-compose/issues/25, thanks @StylianosGakis for the report. ### Chores * Update dependency gradle to v8.7 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/19 * Update detekt to v1.23.6 by @renovate in https://github.com/rafaeltonholo/svg-to-compose/pull/20 * Update dependency com.github.ajalt.clikt:clikt to v4.3.0 by @renovate in https://gitLow4/27/2024
v1.1.0## What's Changed Improvements to SVG handling, add support for other path attributes, and code maintainability ### Features * Add missing path parameters (Issue #4) * Add recursive directory file search * Create DSL to build `PathNode` command class * Improve `String.toComposeColor()` to handle RGB and RGBA colour formats * SVG: * Add `SvgLength` to handle different lengths for width and height on svg node * Calculate strokeWidth and strokeOpacity based on float or percentaLow3/22/2024
v1.0.0## What's Changed * Migrate to KMP in https://github.com/rafaeltonholo/svg-to-compose/pull/7 * Fixes #3 by adding support for group tags on both SVG and XML * Fixes #6 by removing the dependency of xpath and other dependencies. * We still have external dependencies to perform the optimization * Add more platform support, now counting with MacOS, Linux and Windows (mingx64) ## Changelog **Full Changelog**: https://github.com/rafaeltonholo/svg-to-compose/compare/v0.0.4...v1.0.0 #Low3/4/2024

Dependencies & License Audit

Loading dependencies...

Similar Packages

SeekerClawTurn your Solana Seeker (or any Android phone) into a 24/7 personal AI agentv2.0.0
objectbox-javaDatabase for Android and JVM - first and fast, lightweight on-device vector databaseV5.4.2
search🔍 Implement hybrid search using Vespa and FastAPI, blending BM25 and dense semantic retrieval for efficient, accurate information retrieval.main@2026-06-05
excalibase-graphqlExcalibase GraphQL instantly turns your database into a GraphQL API. Built with Spring Boot, it supports schema discovery, subscriptions, and type handling — no manual resolvers needed.main@2026-06-04
claude-terminalManage multiple Claude Code sessions in a single terminal with tabs, session persistence, multi-project workspaces, and git worktree support.main@2026-06-04

More in Databases

milvusMilvus is a high-performance, cloud-native vector database built for scalable vector ANN search
WeKnoraLLM-powered framework for deep document understanding, semantic retrieval, and context-aware answers using RAG paradigm.
ai-real-estate-assistantAdvanced AI Real Estate Assistant using RAG, LLMs, and Python. Features market analysis, property valuation, and intelligent search.
alibabacloud-adb20211201Alibaba Cloud adb (20211201) SDK Library for Python