Slide 1

Slide 1 text

Remove Unused Resources potatotips #51 @konifar / Kyash Inc. 1

Slide 2

Slide 2 text

Do you use Android Lint to detect "unused resources"? 2

Slide 3

Slide 3 text

Lint "unused resources" is useless! It sometimes (or always) tells a lie... Especially in the case of using DataBinding 3

Slide 4

Slide 4 text

Keep clean Android project It's enough to use gradle option shrinkResources and minifyEnabled to shrink apk. But unused resources bother you to inspect code and to search le on project tree in Android Studio. It's better to remove unused resources and keep clean your project to write code easy! 4

Slide 5

Slide 5 text

gradle-unused-resources- remover-plugin https://github.com/konifar/gradle-unused- resources-remover-plugin 5

Slide 6

Slide 6 text

Features Easy to remove unused resources by simple gradle command. Customize extra/exclude les con guration. Support DataBinding & Multi module project. Integrate with CI to send PullRequest automatically. https://gist.github.com/konifar/2f793dd5c4f3064 aad8d757ebb7b093f 6

Slide 7

Slide 7 text

Supported resources - (1) |--res |--anim | |--*.xml |--animator | |--*.xml |--drawable* // drawable-v21 as well | |--*.xml | |--*.png | |--*.jpg | |--*.9.png // 9-patch |--layout* | |--*.xml |--menu | |--*.xml |--mipmap* | |--*.xml | |--*.png 7

Slide 8

Slide 8 text

Supported resources - (2) |--res |--values* // values-ja, values-v23 as well |--attrs*.xml |--bools*.xml |--colors*.xml |--dimens*.xml |--floats*.xml |--ids*.xml |--integers*.xml |--strings*.xml |--styles*.xml |--themes*.xml 8

Slide 9

Slide 9 text

Simple usage Just run gradle command! $ ./gradlew removeUnusedResources ... [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 [menu] ======== Start menu checking ======== ... 9

Slide 10

Slide 10 text

Option 1 : extraRemovers If you want to check unsupported resource le, you can add custom remover settings in app/build.gradle . 10

Slide 11

Slide 11 text

Option 1 : extraRemovers Ex) text_appearance.xml which contains text_appearance's You can add custom remover like this. unusedResourcesRemover { extraRemovers = [ createXmlValueRemover("text_appearance", "style", "style", "style") ] } 11

Slide 12

Slide 12 text

createXmlValueRemover() Name Description leType Pre x of the le name like font , text_appearance resourceName Name to check its existence like @ string /app_name, $. string /app_name tagName Name to extract value from xml like < string name="app_name"> searchType Search regex pattern type. style , drawable , layout , default are supported. 12

Slide 13

Slide 13 text

Option 2 : exludeNames If you want to skip checking some le, you can add white list to excludeNames setting. resources.getIdentifier("img_welcome_${number}", "drawable", context.getPackageName()) unusedResourcesRemover { excludeNames = [ "img_welcome_", // img_welcome.*.xml is never checked. ] } 13

Slide 14

Slide 14 text

Demo 14

Slide 15

Slide 15 text

User voices 15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

18

Slide 19

Slide 19 text

Keep clean your project! 19

Slide 20

Slide 20 text

And "kyash" me https://github.com/konifar/gradle-unused- resources-remover-plugin#donation 20

Slide 21

Slide 21 text

Thanks! 21