Android Drawable Maven Plugin

A Maven plugin for generating Android drawable resources from SVG files. PNG files will be generated from the SVG file at the pixel densities specified. The plugin also allows the flattening of directory structures as well as the packaging of bitmap resources alongside the SVGs

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.github.kingamajick.admp
ArtifactId

ArtifactId

android-drawables-maven-plugin
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Android Drawable Maven Plugin
A Maven plugin for generating Android drawable resources from SVG files. PNG files will be generated from the SVG file at the pixel densities specified. The plugin also allows the flattening of directory structures as well as the packaging of bitmap resources alongside the SVGs
Project URL

Project URL

https://github.com/kingamajick/android-drawables-maven-plugin
Source Code Management

Source Code Management

http://github.com/kingamajick/android-drawables-maven-plugin/tree/master

Download android-drawables-maven-plugin

How to add to project

<plugin>
    <groupId>com.github.kingamajick.admp</groupId>
    <artifactId>android-drawables-maven-plugin</artifactId>
    <version>1.0.0</version>
</plugin>

Dependencies

compile (4)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.0.3
org.apache.maven : maven-core jar 3.0.3
org.apache.xmlgraphics : batik-transcoder jar 1.7
org.apache.xmlgraphics : batik-codec jar 1.7

test (7)

Group / Artifact Type Version
junit : junit jar 4.10
org.apache.maven : maven-plugin-descriptor jar 2.2.1
org.easymock : easymockclassextension jar 3.1
org.powermock : powermock-module-junit4 jar 1.4.11
org.powermock : powermock-api-easymock jar 1.4.11
org.easytesting : fest-reflect jar 1.2
commons-codec : commons-codec jar 1.6

Project Modules

There are no modules declared in this project.

Android-Drawables-Maven-Plugin

The android-drawables-maven-plugin was created to allow the generation of Android drawable artifacts from a SVG source. After originally using the Batik Maven Plugin to perform this task, I found the amount of configuration grew rapidly so I created the android-drawables-maven-plugin to make the process simpler.

Getting Started

Prerequisities

Maven 3.0.3+ installed, see http://maven.apache.org/download.html

Creating a android-drawables artifact

  1. Create a new maven project with a packaging type of android-drawables and add the android-drawables-maven-plugin to its build configuration.

     ....    
     <packaging>android-drawables</packaging>  
     ....
     <build>
         <plugins>
             <plugin>
                 <groupId>com.github.kingamajick.admp</groupId>
                 <artifactId>android-drawables-maven-plugin</artifactId>
                 <version>1.0.0</version>
                 <extensions>true</extensions>
                 <configuration>
                     <rasterizedType>[png|jpg]</rasterizedType>
                 </configuration>
             </plugin>
           ....
         </plugins>
     </build>
    
  2. Create the following directory structure to store the drawable resources

     src/main/svg/          <= Contains any SVG resources to be rasterized
     src/main/resources/    <= Contains any static resources
         |-- ldpi
         |-- mdpi
         |-- hdpi
         |-- xhdpi
         |-- nodpi
         `-- tvdpi
    

The directories may contain sub folders (both for SVG resources and static resources). If this is the case, the resultant name of the file packaged in the will be generated from the directory structure. Given dir1\dir2\image.svg, the resulting image file name will be dir1_dir2_image.png (assuming png is the rasterizedType).

  1. By default the SVG resources are rasterized at the following dimensions.

    Output Scale Factor (relative to the SVG image dimensions)
    drawable-ldpi 0.75
    drawable-mdpi 1.00
    drawable-hdpi 1.50
    drawable-xhdpi 2.00
    If this is not suitable, custom densities can be supplied via the plugin configuration using the following form:

     <configuration>  
     ....  
         <densities>  
             <density>  
                 <name>[drawable-ldpi|drawable-mdpi|drawable-hdpi|drawable-xhdpi|drawable-nodpi|drawable-tvdpi]</name>  
              <scaleFactor></scaleFactor>  
             <density>  
         </densities>  
     ....  
     </configuration>
    

Note: By doing this all densities will have to be specified as the defaults will no longer be generated.
Note: The name must be the expected folder name for that resource, i.e drawable-type. 4. Your project is now ready to be built.

Consuming a android-drawables artifact

  1. In the project to consume a android-drawables artifact, configure the POM as follows:

     <plugin>
         <groupId>com.github.kingamajick.admp</groupId>
         <artifactId>android-drawables-maven-plugin</artifactId>
         <version>1.0.0</version>
         <extensions>true</extensions>
         <executions>
             <execution>
                 <id>Unpack Drawables</id>
                 <phase>initialize</phase>
                 <goals>
                     <goal>unpack</goal>
                 </goals>
                 <configuration>
                     <drawableArtifacts>
                         <drawableArtifact>
                             <groupId>${drawableArtifactGroupId}</groupId>
                             <artifactId>${drawableArtifactArtifactId}</artifactId>
                             <version>${drawableArtifactVersion}</version>
                         </drawableArtifact>
                     </drawableArtifacts>
                     <unpackLocation></unpackLocation>
                 </configuration>
             </execution>
         </executions>
     </plugin>
    

This will unpack the specified artifact(s) during the initialize phase.

Note: All folders will be unpacked into ${unpackLocation}/res rather than ${unpackLocation}

m2e Connector

A m2e connector is available for this plugin at https://github.com/kingamajick/android-drawables-maven-plugin-m2e

Maven Site

The maven site for this project can be found at http://kingamajick.github.com/android-drawables-maven-plugin/

Snapshots

Snapshots of the android-drawables-maven-plugin are available from the Sonatype OSS Repository Hosting Service. To use snapshots, add the following configuration to the pom.

<pluginRepositories>
    <pluginRepository>
        <id>oss-sonatype</id>
        <name>oss-sonatype</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

Versions

Version
1.0.0