Last active
October 3, 2018 03:29
-
-
Save vtthach/1904c8bc5616df3c50fdb73224d973b2 to your computer and use it in GitHub Desktop.
Proguard Meaning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
defaultConfig { | |
multiDexEnabled true // Multiple dex enable only for Android Version >21 (prior v21 see more at: https://developer.android.com/studio/build/multidex.html) | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
// Keep file into main dex | |
multiDexKeepFile file('multidex-config.txt') | |
multiDexKeepProguard file('multidex-config.pro') | |
} | |
buildTypes { | |
debug { | |
minifyEnabled false | |
signingConfig signingConfigs.debug | |
release { | |
shrinkResources true // Shrink resource | |
minifyEnabled true // Shrink code (default useProguard == true -> obfocus and optimize) | |
ext.set("dexprotector.configFile", "${projectDir}/dexprotector.xml") // Deprotector | |
signingConfig signingConfigs.release | |
} | |
} | |
} | |
The getDefaultProguardFile('proguard-android.txt') method gets the default ProGuard settings file that is packaged with the Android plugin. When you build your project, the plugin creates a copy of the settings file in project-dir/build/intermediates/proguard-files/. | |
Tip: For even more code shrinking, try the proguard-android-optimize.txt file located in the same directory. It includes the same ProGuard rules, but with other optimizations that perform analysis at the bytecode level—inside and across methods—to reduce your APK size further and help it run faster. | |
The proguard-rules.pro file is where you can add custom ProGuard rules. By default, this file is located at the root of the module (next to the build.gradle file). | |
dump.txt | |
Describes the internal structure of all the class files in the APK. | |
mapping.txt | |
Provides a translation between the original and obfuscated class, method, and field names. | |
seeds.txt | |
Lists the classes and members that were not obfuscated. | |
usage.txt | |
Lists the code that was removed from the APK. | |
### Customize which resources to keep | |
Create keep.xml at res/raw/keep.xml | |
<?xml version="1.0" encoding="utf-8"?> | |
<resources xmlns:tools="http://schemas.android.com/tools" | |
tools:keep="@layout/l_used*_c,@layout/l_used_a,@layout/l_used_b*" | |
tools:discard="@layout/unused2" /> | |
### Remove unused alternative resources | |
android { | |
defaultConfig { | |
... | |
resConfigs "en", "fr" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment