Remove all unused classes,methods from Android Studio project

前端 未结 3 1783
遇见更好的自我
遇见更好的自我 2021-01-31 14:48

I have used the lint(Analyze->Inspect Code...) and find out unused methods and resources. All the unused resources removed by Refractor->Remove unused R

3条回答
  •  有刺的猬
    2021-01-31 15:31

    Step 1

    Generate usage.txt and mapping.txt with Proguard or R8

    • Add -printusage to your proguard.pro file Run

    • ./gradlew app:minifyReleaseWithProguard or ./gradlew app:minifyReleaseWithR8

    Step 2

    Find class name records that is in usage.txt but not in mapping.txt, those are the unused classes that are removed by Proguard/ R8 It's not hard to write such algorithm but you can consider my approach using Binary Search Tree here

提交回复
热议问题