ProGuard Android Guide - Code Shrinking and Obfuscation

Published: (December 30, 2025 at 10:25 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

Android ProGuard 설정과 문제 해결 방법

Shrinking

  • 사용되지 않는 메서드, 클래스, 필드 등을 제거합니다.

Optimizing

  • 메서드 바이트코드 최적화 및 인라인(inline) 처리를 수행합니다.

Obfuscating

  • 이름을 의미 없는 짧은 문자열로 변경하여 난독화합니다.

Preverifying

  • 클래스에 pre‑verification 정보를 추가합니다.

Keep 규칙 예시

클래스만 keep (멤버는 keep되지 않음)

-keep class com.example.app.data.Task

클래스와 모든 멤버 keep

-keep class com.google.ads.mediation.AdUrlAdapter {
    *;
}

클래스와 특정 메서드만 keep

-keep class com.example.app.data.Tasks {
    public ** component1();
}

내부 serializer 클래스 유지

-keep,includedescriptorclasses class **$$serializer { *; }

멤버만 유지 (클래스를 사용하지 않으면 삭제됨)

-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}

클래스 내 멤버 이름만 유지 (사용되지 않으면 삭제)

-keepclassmembernames public class * extends com.example.base.net.BaseValueObject {
    private ;
}

조건을 충족하는 멤버가 있는 경우 클래스와 멤버를 유지

-keepclasseswithmembers class com.your.package.** {
    public ** component1();
    ;
}

어노테이션 기반 keep

-keep @android.support.annotation.Keep class *

Retrofit 메서드 keep

-keepclasseswithmembers class * {
    @retrofit.http.* ;
}

Log 인터페이스 구현 클래스 멤버 keep

-keepclassmembernames class * implements com.example.log.Log {
    ;
}

와일드카드 사용 (***는 any type)

public static *** parse(***);

3rd 파티 라이브러리 API 호출 시 Request/Response 클래스 keep

-keepclassmembernames class com.example.sdk.** { *; }

개별 클래스 수동 keep (dex 에러 방지)

-keep class com.example.sdk.Models.AllowedCredentials
-keepclassmembers class com.example.sdk.Models.AllowedCredentials { *; }

Enum 클래스 이름 keep

-keep enum com.example.base.e.HasType

상속받은 클래스 난독화 방지 (부모 클래스도 keep)

-keep class com.example.base.mvp.BaseModel
-keepclassmembers class * extends com.example.base.mvp.BaseModel { *; }

Kotlin Built‑ins 로더 keep

-keep class kotlin.reflect.jvm.internal.** { *; }

Common Issues & Solutions

1. referenced class 오류

원인

  • 라이브러리가 참조하는 클래스가 포함되지 않음
  • implementation 의존성으로 추가했지만 해당 클래스가 없고, api 로 하면 포함됨

해결

  • ProGuard 적용 전 문제가 없었다면 런타임에 해당 클래스가 사용되지 않는 것일 수 있음
  • -dontwarn 옵션을 사용하여 경고를 무시
-dontwarn com.example.unused.class.**

2. java.lang.ClassNotFoundException (Enum 등)

  • Enum 클래스 자체도 keep 해야 합니다.

3. IllegalStateException: No BuiltInsLoader implementation was found.

  • Kotlin 내부 클래스를 keep:
-keep class kotlin.reflect.jvm.internal.** { *; }

4. IllegalArgumentException: Unable to create converter for class

  • 부모 클래스의 keep이 누락된 경우 발생합니다.
  • 라이브러리를 implementation 대신 api 로 선언하면 해당 라이브러리와 그 의존성을 함께 포함할 수 있습니다.

References

  • ProGuard Manual
  • Retrofit ProGuard Rules
  • Stack Overflow: keep vs keepclassmembers
Back to Blog

Related posts

Read more »

RxJava Fundamentals - Reactive Programming on Android

RxJava의 기본 개념과 안드로이드에서의 활용법을 알아봅니다. RxJava란? RxJava는 Reactive + Functional Programming을 결합한 라이브러리입니다. 핵심 개념 - 데이터와 처리를 분리하고, 데이터는 처리에 푸시만 합니다. - Threading을 라이브러...