Stay organized with collections
Save and categorize content based on your preferences.
If you have different versions of your app based on different build variants,
create custom keep rules for each variant. For example, if you have a free
tier and a paid tier of your app with different features and dependencies, each
tier should have its own keep rules.
Create keep rules
To create keep rules that are specific to a build variant, add the
proguardFiles property in the corresponding flavor block under
productFlavors. For example, the following build script adds the rules file
flavor2‑rules.pro to the flavor2 product flavor:
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 2025-05-29 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 2025-05-29 UTC."],[],[],null,["# Target a build variant\n\nIf you have different versions of your app based on different build variants,\ncreate custom [keep rules](/topic/performance/app-optimization/add-keep-rules) for each variant. For example, if you have a free\ntier and a paid tier of your app with different features and dependencies, each\ntier should have its own keep rules.\n\nCreate keep rules\n-----------------\n\nTo create keep rules that are specific to a build variant, add the\n`proguardFiles` property in the corresponding *flavor* block under\n`productFlavors`. For example, the following build script adds the rules file\n`flavor2‑rules.pro` to the `flavor2` product flavor: \n\n### Kotlin\n\n android {\n ...\n buildTypes {\n getByName(\"release\") {\n isMinifyEnabled = true\n proguardFiles(\n getDefaultProguardFile(\"proguard-android-optimize.txt\"),\n \"proguard-rules.pro\"\n )\n }\n }\n flavorDimensions.add(\"version\")\n productFlavors {\n create(\"flavor1\") {\n ...\n }\n create(\"flavor2\") {\n proguardFile(\"flavor2-rules.pro\")\n }\n }\n }\n\n### Groovy\n\n android {\n ...\n buildTypes {\n release {\n minifyEnabled true\n proguardFiles\n getDefaultProguardFile('proguard-android-optimize.txt'),\n 'proguard-rules.pro'\n }\n }\n flavorDimensions \"version\"\n productFlavors {\n flavor1 {\n ...\n }\n flavor2 {\n proguardFile 'flavor2-rules.pro'\n }\n }\n }\n\n| **Note:** The `flavor2` product flavor uses rules from three rules files---`flavor2‑rules.pro`, `proguard‑rules.pro`, and `proguard‑android‑optimize.txt`---because the script applies the rules from the release block.\n\nAdditional resources\n--------------------\n\n- [Customize which resources to keep](/topic/performance/app-optimization/customize-which-resources-to-keep) --- Learn how to add keep rules for resources."]]