Skip to content

A maven plugin for packaging and importing drawables, either static or created from SVGs

License

Notifications You must be signed in to change notification settings

kingamajick/android-drawables-maven-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 

Repository files navigation

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.

    OutputScale Factor (relative to the SVG image dimensions)
    drawable-ldpi0.75
    drawable-mdpi1.00
    drawable-hdpi1.50
    drawable-xhdpi2.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>

About

A maven plugin for packaging and importing drawables, either static or created from SVGs

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages