🏴󠁧󠁢󠁥󠁮󠁧󠁿
TechDictionary.org
English
English
  • Introduction
  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • H
  • I
  • K
  • L
  • M
  • N
  • O
  • P
    • ProGuard
  • Q
  • R
  • S
  • T
  • U
  • V
  • W
  • REFERENCES
    • How to be a guru
Powered by GitBook
On this page
Export as PDF
  1. P

ProGuard

ProGuard is a tool for shrinking, optimizing, obfuscating, and stripping unused code in Java and Android applications. It helps reduce APK/AAB size, protect source code from reverse engineering, and improve performance.

🔹 Key Features of ProGuard

  1. Shrinking: Removes unused classes, methods, and fields.

  2. Optimization: Optimizes bytecode for better performance and reduced size.

  3. Obfuscation: Renames classes, methods, and variables to meaningless short names, making it harder to reverse-engineer.

  4. Stripping: Removes unnecessary libraries and code to minimize the application size.

🔹 ProGuard in Android

  • Built into the Android SDK but has been largely replaced by R8 since Android Studio 3.4 (R8 is faster and more efficient).

  • Activated in release mode by enabling minifyEnabled in build.gradle:

    gradleCopyEditbuildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

🔹 Things to Watch Out for

  • May accidentally remove necessary code (especially with reflection, Gson, Retrofit).

  • Requires a proguard-rules.pro file to keep essential components, for example:

    proguardCopyEdit-keep class com.example.model.** { *; }
    -keep class com.google.gson.** { *; }
PreviousPNextQ

Last updated 3 months ago