当前位置: 首页 > 软件库 > 手机/移动开发 > >

gradle-unused-resources-remover-plugin

授权协议 Apache-2.0 License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 东和怡
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Unused Resources Remover for Android

Gradle Plugin that removes unused resources in Android projects.

Features

  • Easy to remove unused resources by simple gradle command
  • Customize extra/exclude files configuration
  • Support DataBinding & Multi module project

Simple usage

build.gradle

buildscript {
  repositories {
    maven { url "https://plugins.gradle.org/m2/" }
  }
  
  dependencies {
    classpath "gradle.plugin.com.github.konifar.gradle:plugin:0.3.3"
  }
}

NOTE: If your gradle version is 2.1 and later, you can use new snippet for plugins DSL.If you want to know more details, see plugin page.

app/build.gradle

apply plugin: "com.github.konifar.gradle.unused-resources-remover"

Run

$ ./gradlew removeUnusedResources

Hook to Clean Project(Optional)

If you want to hook to Clean Project, add following code at the end.

app/build.gradle

clean.dependsOn(removeUnusedResources)

Advanced usage

This plugin checks some basic resource files below.

|--res
   |--anim
   |  |--*.xml
   |--animator
   |  |--*.xml
   |--drawable*
   |  |--*.xml
   |  |--*.png
   |  |--*.jpg
   |  |--*.9.png // 9-patch
   |--layout*
   |  |--*.xml
   |--menu
   |  |--*.xml
   |--mipmap*
   |  |--*.xml
   |  |--*.png
   |--values*
      |--attrs*.xml
      |--bools*.xml
      |--colors*.xml
      |--dimens*.xml
      |--floats*.xml
      |--ids*.xml
      |--integers*.xml
      |--strings*.xml
      |--styles*.xml
      |--themes*.xml

If you want to check other files, you can add custom remover settings in app/build.gradle.

Here is two example.

  • fonts.xml (actually same format with strings.xml)
  • text_appearance.xml (actually same format with styles.xml)
unusedResourcesRemover { 
  extraRemovers = [
    createXmlValueRemover("fonts", "string", "string"), // fonts.xml
    createXmlValueRemover("text_appearance", "style", "style", "style") // text_appearance.xml
  ]
  ...
}

There are other optional configuration below

unusedResourcesRemover {
  ...
  // Write file or directory names
  excludeNames = [
    "strings.xml", // strings.xml is never checked
    "res/drawable" // drawable* dirs are never checked
  ]
  
  // When dryRun option is true, unused files are not removed.
  dryRun = true // default false
}

To know more, See UnusedResourcesRemoverExtension

Contributing

This project is under development.

I'm always welcome your contribution! Feel free to report Issue or send Pull Request!

Project structure

plugin/         - The main module of Gradle plugin
example/        - An example android project that uses this plugin
example-module/ - An example module that are used in example

Download repository

$ git clone git@github.com:konifar/gradle-unused-resources-remover-plugin.git
$ cd gradle-unused-resources-remover-plugin

Edit build.gradle

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

+//    classpath "gradle.plugin.com.github.konifar.gradle:plugin:0.3.3"
-    classpath "gradle.plugin.com.github.konifar.gradle:plugin:0.3.3"
    // For mavenLocal
+    classpath 'com.github.konifar.gradle:unused-resources-remover:0.3.3'
-//    classpath 'com.github.konifar.gradle:unused-resources-remover:0.3.3'
    }

Install to local maven

$ cd plugin
$ ./../gradlew assemble install

Run example

$ cd example
$ ./../gradlew removeUnusedResources
...
$ > Task :example:removeUnusedResources 
$ extraRemovers:
$   fileType: font, resourceName: string, type: DEFAULT
$   fileType: text_appearance, resourceName: style, type: STYLE
$ excludeNames:
$   fonts.xml
$ dryRun: false
$ [layout] ======== Start layout checking ========
$ [layout] example
$ [layout]   Remove unused_layout.xml
$ [layout]   Complete to remove files.
$ [layout] example-module
$ [layout]   No unused layout files.
$ [layout] plugin
...

Donation

If this plugin helps you, I would be so happy.

I'm welcome your tip by Kyash! My account name is konifar.

License

Copyright 2018 Yusuke Konishi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 相关资料
  • unused是用来检查Go代码未使用的常量,变量,函数和类型的。 安装 go get honnef.co/go/unused/cmd/unused 用法 unused -hel 示例 $ time unused cmd/go/usr/lib/go/src/cmd/go/generate.go:375:21: identLength is unused/usr/lib/go/src/cmd/go/t

  • Comment Remover 用来删除各种源码文件中的注释,支持的语言包括:汇编, Pascal, Java, C, C++, D, and Python.

  • Alpha Channel Remover 是 Mac OS X 应用,允许用户从图片中移除 alpha(透明度),几秒的时间你就可以移除多个文件的透明度。

  • By now you should have a good idea of how Jest can help you test your applications. If you're interested in learning more, here's some related stuff you might want to check out. 浏览文档 Learn about Snaps

  • To learn more about the Basic Elements To see the full API document in Markdown format, see APIs To contribute to Gio.js's code base, read Developer Guide

  • slug : Slugifies strings, even when they contain Unicode.Make strings URL-safe. eslint cn : 可组装的JavaScript和JSX检查工具 eslint airbnb : git cheat sheet webpackjs yargs