Android SVG Drawable 插件使用教程

随笔6天前发布 景甜
14 0 0

Android SVG Drawable 插件使用教程

androidsvgdrawable-pluginGradle plugin that generates qualified, density specific PNG drawables from SVG files at build time for your Android projects.项目地址:https://gitcode.com/gh_mirrors/an/androidsvgdrawable-plugin

1. 项目的目录结构及介绍

Android SVG Drawable 插件的 GitHub 仓库目录结构如下:




androidsvgdrawable-plugin/


├── plugin/


│   ├── src/


│   └── build.gradle


├── sample/


│   ├── src/


│   └── build.gradle


├── .gitignore


├── .travis.yml


├── CHANGELOG.md


├── LICENSE


├── README.md

plugin/:包含插件的主要代码和资源。sample/:包含插件的示例项目,展示了如何使用插件。.gitignore:Git 忽略文件配置。.travis.yml:Travis CI 配置文件。CHANGELOG.md:项目更新日志。LICENSE:项目许可证。README.md:项目说明文档。

2. 项目的启动文件介绍

项目的启动文件主要是 plugin/build.gradlesample/build.gradle

plugin/build.gradle

该文件定义了插件的构建配置,包括依赖项、任务和插件的版本等信息。

sample/build.gradle

该文件定义了示例项目的构建配置,展示了如何应用插件并配置任务。

3. 项目的配置文件介绍

build.gradle

build.gradle 文件中,你需要应用插件并配置任务。以下是一个典型的配置示例:




apply plugin: 'com.android.application'


apply plugin: 'androidsvgdrawable'


 


// 创建一个任务将 SVG 转换为 PNG


task svgToPng(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask) {


    // 配置,参见示例项目


}

pom.xml

如果你使用 Maven,可以在 pom.xml 中添加插件配置:




<plugin>


    <groupId>fr.avianey.androidsvgdrawable</groupId>


    <artifactId>maven-plugin</artifactId>


    <executions>


        <execution>


            <id>gendrawable-png</id>


            <configuration>


                <!-- 配置,参见示例项目 -->


            </configuration>


            <phase>initialize</phase>


            <goals>


                <goal>gen</goal>


            </goals>


        </execution>


    </executions>


</plugin>

通过以上配置,你可以在构建过程中自动生成密度特定的 PNG 资源。

androidsvgdrawable-pluginGradle plugin that generates qualified, density specific PNG drawables from SVG files at build time for your Android projects.项目地址:https://gitcode.com/gh_mirrors/an/androidsvgdrawable-plugin

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...