[ Web Proxy ]
URL:
Viewing: http://developer.android.com/topic/performance/app-optimization/keep-rules-best-practices [Back]  [Original]

Follow the best practices  |  App quality  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Follow the best practices Stay organized with collections Save and categorize content based on your preferences.

While working with keep rules, it's important to reach the right amount of specificity to make sure you see benefits while maintaining your app's behaviour. See the following sections to learn about good patterns as well as things to avoid in keep rules.

Good patterns in keep rules

Well-defined keep rules are as specific as possible and adhere to the following patterns:

If you can't adhere to these guidelines, you can temporarily isolate the code that needs to be kept in a dedicated package and apply your keep rule to the package. However, this isn't a solution for the long term. To learn more, see Adopt optimizations incrementally. To use a keep rule for a package define a keep rule as shown in the following example:

-keepclassmembers class com.example.pkg.** { *; }

Things to avoid

The keep rule syntax has many options, but for measurable sustainable performance benefits we recommend not using the following:

If you're unable to follow these rules, you might be using a lot of open-ended reflection, and should either avoid the reflection or avoid the library using reflection (see the Gson case study).

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-05-19 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-05-19 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page