• Stars
    star
    364
  • Rank 112,068 (Top 3 %)
  • Language
    Groovy
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Gradle Plugin that removes unused resources in Android projects.

Unused Resources Remover for Android

CircleCI

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 [email protected]: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.

More Repositories

1

android-material-design-icon-generator-plugin

This plugin help you to set material design icon to your project.
Java
2,414
star
2

fab-transformation

Support Floating Action Button transformation for Android
Java
767
star
3

droidkaigi2016

DroidKaigi 2016 official Android conference app in Tokyo.
Java
662
star
4

droidkaigi2018-flutter

The unofficial conference app for DroidKaigi 2018 Tokyo
Dart
509
star
5

material-cat

Cat photos app for Material Design Animation sample.
Kotlin
394
star
6

android-strings-search-plugin

This plugin makes it easy to search text in strings resources.
Java
232
star
7

master-of-android-theme

Practical demo app to master Android Theme for DroidKaigi 2019
Kotlin
65
star
8

kotoha

Kotoha is useful chrome extension that help you to quote a good phrase.
JavaScript
46
star
9

twipe

Twipe is the fast and easy to use material design Twitter client.
40
star
10

sketch-export-sample

Sample repository to export the icons in Sletch file to iOS/Android projects.
Swift
35
star
11

android-theme-attrs-to-markdown-table

Simple tool to parse Android theme attrs.xml to markdown table
Python
26
star
12

annict-android

Annict Android app. https://annict.com
Java
25
star
13

creditcard-input-helper

Simple helper library to input credit card number, expiry month/year and security code on Android
Kotlin
25
star
14

gas-slack-channels-auto-archive

『100日後にアーカイブされるSlackチャネル』を動かすGoogle Apps Script
TypeScript
17
star
15

flutter-for-non-engineers

エンジニア以外の職種の方がFlutterでの開発を通してなんとなくアプリ開発について知るためのリポジトリです
Dart
12
star
16

FloatingActionButtonSpec

This is floating action button sample based on material design spec. http://www.google.com/design/spec/components/buttons-floating-action-button.html#buttons-floating-action-button-floating-action-button
Java
9
star
17

FacebookSdk4Sample

Facebook SDK v4 sample
Java
6
star
18

material-typography-sample

Java
5
star
19

scroll_technique

Android Material Design Scroll Technique
Java
5
star
20

kyash-barcode-generator

Simple web tool to generate Kyash barcode.
Vue
4
star
21

droidkaigi-session

DroidKaigiセッションの草稿です。私がもがき苦しむ様子が垣間見えます。
4
star
22

presentation-android-resource-refactoring

仕事でAndroidリソースのリファクタリングをして美しくなったので、その知見を発表するための雑メモ置き場です
4
star
23

nice_button_sample

Nice button flow sample.
Java
3
star
24

ActivityAnimationSample

Java
3
star
25

android-layout-performance

Java
3
star
26

English

This is my English learning repository.
3
star
27

vectalign-plugin

This plugin help you to create AnimatedVectorDrawable by using vectalign. https://github.com/bonnyfone/vectalign
Java
2
star
28

go-srt

Parser for the simple SubRip (.srt) file.
Go
2
star
29

about-me

2
star
30

android-studio-plugin-sampler

Code examples for AndroidStudio plugin.
2
star
31

danger-htmllint

danger plugin to run htmllint https://www.npmjs.com/package/htmllint
Ruby
2
star
32

EndlessScroll

EndlessScroll is Android library for endless scrolling of list.
Java
2
star
33

react-native-notes

Private notes for react native
1
star
34

nearby-chat

This app is sample of Nearby Messages API.
Java
1
star
35

konifar.github.io

HTML
1
star
36

i18nLocalizableStringsExample

i18n Localizable.strings example.
Ruby
1
star
37

android-studio-plugin-hello-world

Android Studio Hello World Sample
Java
1
star
38

TranslationSample

This is translation sample project.
Java
1
star
39

animated-vector-drawable-samples

Android AnimatedVectorDrawable samples
Java
1
star
40

android-layout-refactor

Android layout refactoring training
Java
1
star
41

yapcasia-scenario

YAPC::Asia Hachiojiのトーク準備野営地 https://github.com/hachiojipm/yapcasia-8oji-2016mid-timetable/issues/16
1
star
42

kotoha-server

Kotoha help you to quote a good phrase.
Ruby
1
star
43

kotoha-android

Kotoha for Android. Kotoha is useful chrome extension that help you to quote a good phrase.
Java
1
star