Remove Unused Resources

Remove Unused Resources

potatotips #51

35e08efcf39d692f540047fb756eb4e3?s=128

konifar

May 23, 2018
Tweet

Transcript

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

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

  3. Lint "unused resources" is useless! It sometimes (or always) tells

    a lie... Especially in the case of using DataBinding 3
  4. 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
  5. gradle-unused-resources- remover-plugin https://github.com/konifar/gradle-unused- resources-remover-plugin 5

  6. 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
  7. 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
  8. 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
  9. 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
  10. Option 1 : extraRemovers If you want to check unsupported

    resource le, you can add custom remover settings in app/build.gradle . 10
  11. Option 1 : extraRemovers Ex) text_appearance.xml which contains text_appearance's <style>

    You can add custom remover like this. unusedResourcesRemover { extraRemovers = [ createXmlValueRemover("text_appearance", "style", "style", "style") ] } 11
  12. 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
  13. 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
  14. Demo 14

  15. User voices 15

  16. 16

  17. 17

  18. 18

  19. Keep clean your project! 19

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

  21. Thanks! 21