How to avoid unused resources and code from an Android Library Project getting into my APK?

前端 未结 3 535
[愿得一人]
[愿得一人] 2021-02-08 17:01

I have an Android Library Project in my Eclipse workspace, that I use as a unique toolbox. By chance(1), I just discovered that resources from the library (xml animations, xml l

3条回答
  •  灰色年华
    2021-02-08 17:58

    The new Android build system has a resource stripping mechanism built in that can be run as a final step on the build process. Use it in addition to removing resources that lint identifies.

    Note that the resource stripping mechanism is particularly useful in conjunction with Proguard (also bundled with the build system) and when you're using libraries in your project. The idea is:

    • Proguard removes classes that you're not using, including those that came from libraries.
    • The above process can delete code references to resources included with those libraries.
    • Those unreferenced resources can thus be stripped from the APK, because there's no code that uses them anymore.

    Removing unused resources that lint identifies is still useful because removing them:

    • Speeds up your build
    • Reduces your project's maintenance burden.

提交回复
热议问题