Skip to content

How to use with flavor

Carla Vaquero edited this page Jun 28, 2017 · 3 revisions

The use of the androidsvgdrawable-plugin in conjunction with flavors is straightforward.

Add a source directory for each flavor

Generated drawable will be written in a directory specific to each flavor :

sourceSets{
    main.res.srcDirs = [main.res.srcDirs, "build/generated/res/main"]
    flavor1.res.srcDirs = [flavor1.res.srcDirs, "build/generated/res/flavor1"]
    flavor2.res.srcDirs = [flavor2.res.srcDirs, "build/generated/res/flavor2"]
}

Remember that building your application against a flavor will merge resources in order. Flavor specific drawable will only be overriden by buildType specific resources. See http://tools.android.com/tech-docs/new-build-system/resource-merging for more informations.

Configure a task for each flavour

For each flavor, configure a regular SvgDrawableTask that will be executed before the android preBuild task. A best practice is to put SVG that are specific to a flavor into a flavor suffixed directory.

task svgToPngFlavor1(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask) {
    // pick SVG from a flavor suffixed directory
    from = file('src/main/svg-flavor1')
    // specify the android res folder
    to = file('build/generated/res/flavor1')
    // let generate PNG for the following densities only
    targetedDensities = ['ldpi', 'hdpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
    // output format of the generated resources
    outputFormat = 'PNG'
    // ...
}

It is currently impossible to share SVG accross more than one flavor unless you put it within the resources of the main sourceSet.