android-proguard-setup

Configure ProGuard/R8 for Android release builds with safe defaults

16 stars

Best use case

android-proguard-setup is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Configure ProGuard/R8 for Android release builds with safe defaults

Teams using android-proguard-setup should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/android-proguard-setup/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/tools/android-proguard-setup/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/android-proguard-setup/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How android-proguard-setup Compares

Feature / Agentandroid-proguard-setupStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Configure ProGuard/R8 for Android release builds with safe defaults

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Android ProGuard/R8 Setup

Configures ProGuard/R8 code minification and resource shrinking with safe default rules.

## Prerequisites

- Android project with Gradle
- Kotlin DSL (build.gradle.kts)

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| project_path | Yes | . | Android project root |

## Process

### Step 1: Create ProGuard Rules File

Create or update `app/proguard-rules.pro` with safe defaults:

```bash
cat > app/proguard-rules.pro << 'EOF'
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in the Android SDK.

# Keep line numbers for debugging stack traces
-keepattributes SourceFile,LineNumberTable

# Hide the original source file name
-renamesourcefileattribute SourceFile

# Keep data classes and their fields
-keepclassmembers class * {
    @kotlinx.serialization.SerialName <fields>;
}

# Keep Parcelables
-keepclassmembers class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

# Keep custom views
-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

# Keep native methods
-keepclasseswithmembernames class * {
    native <methods>;
}
EOF
```

**Note:** If `proguard-rules.pro` already exists, ask the user if they want to:
- Replace with safe defaults
- Append safe defaults to existing rules
- Keep existing rules as-is

### Step 2: Enable Minification in build.gradle.kts

Update `app/build.gradle.kts` to enable ProGuard/R8:

```kotlin
android {
    // ... existing config ...

    buildTypes {
        release {
            isMinifyEnabled = true
            isShrinkResources = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
}
```

**Detection logic:**
- Check if `buildTypes.release` already exists
- Check if `isMinifyEnabled` is already set
- Preserve existing `proguardFiles` if present, append if needed

## Verification

**MANDATORY:** Run these commands:

```bash
# Verify ProGuard rules file exists
test -f app/proguard-rules.pro && echo "✓ ProGuard rules exist"

# Verify minification is enabled
grep "isMinifyEnabled = true" app/build.gradle.kts && echo "✓ Minification enabled"

# Verify resource shrinking is enabled
grep "isShrinkResources = true" app/build.gradle.kts && echo "✓ Resource shrinking enabled"
```

**Expected output:**
- ✓ ProGuard rules exist
- ✓ Minification enabled
- ✓ Resource shrinking enabled

## Outputs

| Output | Location | Description |
|--------|----------|-------------|
| ProGuard rules | app/proguard-rules.pro | Safe default keep rules |
| Build config | app/build.gradle.kts | Minification enabled |

## Troubleshooting

### "Build fails with ProGuard error"
**Cause:** ProGuard removed required classes
**Fix:** Add keep rules for the failing classes to proguard-rules.pro

### "App crashes on release but not debug"
**Cause:** ProGuard obfuscated code that uses reflection
**Fix:** Add keep rules for classes used via reflection

## Library-Specific ProGuard Rules

Add these rules based on your project dependencies:

### Retrofit/OkHttp
```proguard
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}
```

### Gson
```proguard
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.google.gson.** { *; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keepclassmembers,allowobfuscation class * {
    @com.google.gson.annotations.SerializedName <fields>;
}
```

### Kotlin Serialization
```proguard
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt
-keepclassmembers class kotlinx.serialization.json.** {
    *** Companion;
}
```

### Health Connect
```proguard
-keep class androidx.health.connect.client.** { *; }
-keep class androidx.health.platform.client.** { *; }
```

### Room
```proguard
-keep class * extends androidx.room.RoomDatabase
-keep @androidx.room.Entity class *
```

## ProGuard Test Configuration

**Important:** Test libraries should NEVER be in release builds. They are `androidTestImplementation` only.

If you need to run instrumented tests on release builds (e.g., to verify signing), use a separate test ProGuard file:

**Step 1: Create** `app/proguard-rules-androidTest.pro`:

```proguard
# Keep EVERYTHING in test APK - we only care about signing, not size
-dontobfuscate
-dontoptimize
-dontshrink
-keep class ** { *; }
```

**Step 2: Update** `app/build.gradle.kts`:

```kotlin
android {
    buildTypes {
        release {
            isMinifyEnabled = true
            signingConfig = signingConfigs.getByName("release")
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            // Keep-all rules for test APK only
            testProguardFiles("proguard-rules-androidTest.pro")
        }
    }
    testBuildType = "release"
}
```

**Result:**
- App APK: Minified with release key ✅
- Test APK: Not minified, signed with release key ✅
- Both have matching signatures for instrumentation ✅

## Completion Criteria

- [ ] `app/proguard-rules.pro` exists with safe defaults
- [ ] `isMinifyEnabled = true` in app/build.gradle.kts
- [ ] `isShrinkResources = true` in app/build.gradle.kts
- [ ] ProGuard rules syntax is valid

Related Skills

conductor-setup

16
from diegosouzapw/awesome-omni-skill

Initialize project with Conductor artifacts (product definition, tech stack, workflow, style guides)

cc-soul-setup

16
from diegosouzapw/awesome-omni-skill

Build cc-soul from source (requires cmake, make, C++ compiler)

android-signing-config

16
from diegosouzapw/awesome-omni-skill

Configure Android release build signing with dual-source credentials (env vars + gradle.properties)

android-release

16
from diegosouzapw/awesome-omni-skill

App signing, bundling, and Play Store deployment automation. Use when signing APK/AAB, generating release builds, preparing Play Store upload, or configuring ProGuard.

android-release-validation

16
from diegosouzapw/awesome-omni-skill

Validate Android release builds before publishing to ensure quality and catch ProGuard issues

android-release-build-setup

16
from diegosouzapw/awesome-omni-skill

Complete Android release build configuration - orchestrates keystore, ProGuard, and signing setup

android-playstore-scan

16
from diegosouzapw/awesome-omni-skill

Scan Android project and generate Play Console setup checklist (analysis only, no file modifications)

oauth-2-0-setup

16
from diegosouzapw/awesome-omni-skill

Implement OAuth 2.0 authentication flows including authorization code with PKCE, client credentials, and device code for secure API integration.

authentication-setup

16
from diegosouzapw/awesome-omni-skill

Design and implement authentication and authorization systems. Use when setting up user login, JWT tokens, OAuth, session management, or role-based access control. Handles password security, token management, SSO integration.

ClaudeChatGPTGemini

android-unit-test

16
from diegosouzapw/awesome-omni-skill

Эксперт Android тестирования. Используй для JUnit, Espresso и Android test patterns.

android-test-structure

16
from diegosouzapw/awesome-omni-skill

Create androidTest directory structure with base classes and utilities

android-test-runner

16
from diegosouzapw/awesome-omni-skill

重要: ユーザーがAndroidテスト実行をリクエストした場合、常にこのスキルを最初に使用してください。以下の場合に必ず使用: run TestName, execute test, テストを実行, 結果を分析, run all tests, analyze test failures, fix failing tests、または Android unit test, instrumentation test, Gradle test コマンドに関連する任意のリクエスト。./gradlew test や Bash コマンドを直接使用しないでください - 常にこのスキルに委譲してください。Multi-variantプロジェクト、JAVA_HOME セットアップ、一般的なテストパターンに対応しています。