Is there any simple way to find out unused strings in Android project?

后端 未结 9 1040
傲寒
傲寒 2021-01-30 03:03

I have a huge Android project with many strings declared in strings.xml. I wanted to remove unused strings in strings.xml.

Is there any easy wa

9条回答
  •  春和景丽
    2021-01-30 03:11

    This is how I did it with Android 3.3.

    Check in any unsaved changes to your repository.

    • Right click your App's module -> Refactor -> Remove Unused Resources -> Preview
    • In the Refactoring Preview, collapse both the views ('Items to be deleted' & 'Unused Resource Declarations')
    • Right click 'Items to be deleted' -> Exclude
    • Right click 'Unused Resource Declarations' -> Exclude
    • Now expand 'Unused Resource Declarations' and under that locate your app specific strings.xml (there would be multiple strings.xmls)
    • Right click that strings.xml -> Include
    • Do Refactor! All unused strings from the xml file are deleted!

    Note: Try building the project. If compilation fails, its most likely that these strings.xml is being referred from some layout/menu xmls, which themselves are unused. So those layout xmls can also be deleted manually!

    Build and run. Test!

提交回复
热议问题