proguard-rules.pro


Overview

The `proguard-rules.pro` file is a configuration file used by the [ProGuard](https://www.guardsquare.com/en/products/proguard) tool in Android projects to control code shrinking, optimization, obfuscation, and preverification during the build process. ProGuard helps reduce the size of the APK by removing unused code and renaming classes and members to short, meaningless names, thereby improving app performance and security against reverse engineering.

This file contains **project-specific ProGuard rules** that extend or override the default set of rules applied by the Android build system. It allows developers to specify which classes or members should be kept (excluded from removal or obfuscation), maintain debugging information, or configure specific behaviors for third-party libraries.


Detailed Explanation of Contents

Since `proguard-rules.pro` is a configuration file rather than a source code file with classes or functions, the documentation focuses on the key directives, their purpose, and usage examples.

Important Directives and Comments

1. Inclusion of Default ProGuard Rules

# By default, the flags in this file are appended to flags specified
# in /Users/stoyan/Library/Android/sdk/tools/proguard/proguard-android.txt

2. Adding Project-Specific Keep Options

# Add any project specific keep options here:

3. Preserving JavaScript Interfaces in WebView

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

4. Preserving Debugging Information

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

5. Rules for Crashlytics

# For Crashlytics
-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**

Usage Examples

Example 1: Keeping a Class with Its Public Methods

-keep class com.example.MyClass {
    public *;
}

Example 2: Keeping All Classes in a Package

-keep class com.example.mypackage.** { *; }

Example 3: Keeping a WebView JS Interface

-keepclassmembers class com.example.MyJSInterface {
    public *;
}

Important Implementation Details


Interaction with Other Parts of the System

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

Visual Diagram: Flowchart of proguard-rules.pro Role and Workflow

flowchart TD
    A[Source Code & Libraries] --> B[Compile to Bytecode]
    B --> C[Default ProGuard Rules (proguard-android.txt)]
    C --> D[Project-Specific Rules (proguard-rules.pro)]
    D --> E[ProGuard Processing]
    E --> F[Optimized & Obfuscated Bytecode]
    F --> G[APK Packaging]
    G --> H[Release APK]
    subgraph ProGuard Configuration
        C
        D
    end

Summary

For more information on ProGuard and rule syntax, refer to the official guide: [Android ProGuard Guide](https://developer.android.com/studio/build/shrink-code) [ProGuard Manual](https://www.guardsquare.com/en/products/proguard/manual)