Skip to content

feat: R8 난독화 및 리소스 축소 활성화#379

Merged
unam98 merged 2 commits intodevelopfrom
feature/enable-r8
Apr 4, 2026
Merged

feat: R8 난독화 및 리소스 축소 활성화#379
unam98 merged 2 commits intodevelopfrom
feature/enable-r8

Conversation

@unam98
Copy link
Copy Markdown
Collaborator

@unam98 unam98 commented Apr 4, 2026

Summary

  • 릴리즈 빌드에 R8 난독화(minifyEnabled true) 및 리소스 축소(shrinkResources true) 적용
  • 서드파티 공식 문서 기반 ProGuard rules 작성 (Firebase Crashlytics, Kakao SDK, Gson)
  • consumer rules로 자동 적용되는 라이브러리는 별도 규칙 미추가 (Retrofit, OkHttp, Kotlin Serialization, Glide, Naver Map SDK, DataBinding, Hilt)

AAB 용량 비교

용량 비고
난독화 전 54.5MB (57,141,698 bytes) minifyEnabled false
난독화 후 46.8MB (49,119,764 bytes) minifyEnabled true + shrinkResources true
절감량 -7.6MB (14% 감소)

ProGuard Rules 근거

각 규칙의 공식 근거는 PR 코멘트에 인라인으로 첨부합니다.

Test Plan

  • 릴리즈 AAB 빌드 성공 확인
  • 카카오 로그인 정상 동작 확인
  • Retrofit API 호출 정상 동작 확인 (Gson/Kotlin Serialization 직렬화)
  • Naver Map 정상 렌더링 확인
  • Firebase Crashlytics 크래시 리포트 난독화 해제 확인
  • Glide/Coil 이미지 로딩 정상 확인

Summary by CodeRabbit

  • Chores
    • Enabled code and resource minification for release builds to reduce app size and improve performance.
    • Updated obfuscation/shrinking rules to better preserve crash reporting data and key third‑party library models for more reliable diagnostics.

릴리즈 빌드에 minifyEnabled true, shrinkResources true 적용.
공식 문서 기반 ProGuard rules 작성 (Firebase Crashlytics, Kakao SDK, Gson).
AAB 용량 54MB → 46.8MB (14% 감소).
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 192f48f4-c7bb-40c3-b50f-bd85b424e464

📥 Commits

Reviewing files that changed from the base of the PR and between 068be1d and adc6078.

📒 Files selected for processing (1)
  • app/proguard-rules.pro

📝 Walkthrough

Walkthrough

Enables code minification and resource shrinking for release builds in Gradle and replaces ProGuard rules: adds Crashlytics-related keeps, retains Kakao SDK model fields, and removes a previous Gson TypeAdapter keep rule.

Changes

Cohort / File(s) Summary
Build Configuration
app/build.gradle
Switched android.buildTypes.release.minifyEnabled from false to true and added shrinkResources true.
ProGuard / R8 Rules
app/proguard-rules.pro
Rewrote rules header; added Crashlytics-related keeps (SourceFile, LineNumberTable, keep exception subclasses); retained Kakao SDK model field preservation (-keep class com.kakao.sdk.**.model.* { <fields>; }); removed former Gson TypeAdapter keep rule.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 I nibble bytes and tidy strings so neat,

I tuck away fields and keep crash traces sweet,
Minify the paths where mobile hopsters run,
Shrink the baggage — lighter builds, here we come! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main changes: enabling R8 obfuscation and resource shrinking for release builds, which matches the primary modifications in build.gradle and proguard-rules.pro.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/enable-r8

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

buildTypes {
release {
minifyEnabled false
minifyEnabled true
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공식 근거: Android 공식 문서 — 앱 축소, 난독화 및 최적화

R8은 기본적으로 코드 축소, 리소스 축소, 난독화, 최적화를 수행합니다.
minifyEnabled true로 R8을 활성화하고, shrinkResources true로 사용되지 않는 리소스를 제거합니다.

AGP 8.13.2 기준 R8은 compatibility mode(기본)로 동작하며, 각 라이브러리의 consumer rules를 자동으로 병합합니다.

# public *;
#}
# --- Firebase Crashlytics ---
# 난독화된 스택 트레이스를 읽을 수 있도록 소스 파일명/라인 번호 유지
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공식 근거: Firebase Crashlytics — Get readable crash reports

To get readable (deobfuscated) crash reports, add the following lines to your ProGuard configuration:

-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception

-renamesourcefileattribute SourceFile은 소스 파일명을 "SourceFile"로 통일하여 APK 크기를 추가 절감하면서도 Crashlytics mapping으로 원본 파일명을 복원할 수 있게 합니다.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정정: 두 가지 부정확한 부분이 있었습니다.

  1. -keep public class * extends java.lang.Exception은 공식 문서에서 Optional로 표시되어 있습니다. 필수가 아니라 선택 사항입니다. 다만 커스텀 Exception 클래스명 보존을 위해 유지합니다.

  2. -renamesourcefileattribute SourceFileFirebase 공식 문서에 포함되지 않은 규칙입니다. ProGuard/R8 커뮤니티에서 널리 쓰이는 관행이며, Crashlytics mapping 파일이 원본 파일명을 복원할 수 있어 호환은 되지만 공식 근거로 제시한 것은 부적절했습니다. 제거합니다.

# 공식 문서: https://firebase.google.com/docs/crashlytics/get-deobfuscated-reports?platform=android
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-renamesourcefileattribute SourceFile
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공식 근거: Kakao Developers — Getting Started (축소/난독화 설정)

To enable shrinking, obfuscation, and optimization when building the release version of your app, add the following codes in the ProGuard rules file to exclude the Kakao SDK from shrinking and obfuscation:

-keep class com.kakao.sdk.**.model.* { <fields>; }

Kakao SDK는 model 클래스에서 Gson 리플렉션을 사용하므로 필드를 유지해야 합니다. v2-user AAR에는 AppLifecycleObserver keep만 포함되어 있어, model 규칙은 수동 추가가 필요합니다.

-keep class com.kakao.sdk.**.model.* { <fields>; }
-keep class * extends com.google.gson.TypeAdapter No newline at end of file

# --- Gson ---
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공식 근거:

Gson 2.11+ 부터 기본 consumer rules가 포함되어야 하지만, 현재 사용 중인 Gson 2.13.2 JAR에는 META-INF/proguard/ 디렉터리가 포함되어 있지 않아 수동 추가가 필요합니다.

TypeAdapter keep: Gson이 리플렉션으로 커스텀 TypeAdapter를 찾으므로 난독화 시 클래스명이 바뀌면 런타임 오류 발생.

@SerializedName keep: 이 프로젝트에서 Gson을 사용하는 DTO (RequestDeleteUploadCourse, RequestPatchPublicCourse, ResponseGetRefreshToken 등 9개 파일)의 필드명을 유지해야 JSON 직렬화가 정상 동작합니다.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정정: Gson 2.13.2 JAR에 consumer rules가 없다는 주장은 오류였습니다.

확인 결과 META-INF/proguard/gson.pro (3,180 bytes)가 정상적으로 포함되어 있습니다. 이전 확인 시 sources JAR을 조회한 것으로 추정됩니다.

따라서 proguard-rules.pro의 Gson 수동 규칙(TypeAdapter keep, @SerializedName keep)은 중복이므로 제거합니다.

consumer rules 자동 적용 목록에 Gson도 추가해야 합니다.

# 각 라이브러리의 공식 문서 또는 공식 저장소에 근거한 규칙만 포함합니다.
# consumer rules로 자동 적용되는 라이브러리는 별도 규칙을 추가하지 않습니다.
# (Retrofit, OkHttp, Kotlin Serialization, Glide, Naver Map SDK, DataBinding, Hilt)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consumer rules 자동 적용 확인 결과 (수동 규칙 추가 불필요):

라이브러리 consumer rules 위치 확인 방법
Retrofit 2.9.0 META-INF/proguard/retrofit2.pro (JAR 내장) 공식 docs — "R8/ProGuard users: rules are included automatically"
OkHttp 4.12.0 META-INF/proguard/okhttp3.pro (JAR 내장) 공식 GitHub
Kotlin Serialization 1.10.0 META-INF/com.android.tools/r8/ (JAR 내장, R8 전용 규칙 포함) PR #2092
Glide 5.0.5 proguard.txt (AAR 내장) 공식 docs
Naver Map SDK 3.23.2 proguard.txt (AAR 내장 — NativeApi, geometry, JNI 등) AAR 직접 확인
DataBinding 8.13.2 proguard.txt (AAR 내장) AAR 직접 확인
Hilt 2.56.2 KSP가 META-INF/proguard/ 규칙을 자동 생성 공식 docs

@unam98 unam98 self-assigned this Apr 4, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/build.gradle`:
- Around line 66-67: Add a ProGuard/R8 keep rule to app/proguard-rules.pro to
prevent drawable fields referenced only via getIdentifier() from being removed;
the dynamic lookups occur in ContextExt (the functions that call getIdentifier)
and the BindingAdapter that resolves stamp drawables, so add a rule to keep the
R$drawable fields (or a narrower rule matching your stamp drawable name pattern)
so those resources aren’t stripped in release builds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 58337af5-8093-406e-bc21-40fd4a006731

📥 Commits

Reviewing files that changed from the base of the PR and between 9cde977 and 068be1d.

📒 Files selected for processing (2)
  • app/build.gradle
  • app/proguard-rules.pro

- Gson 2.13.2 JAR에 consumer rules(gson.pro)가 포함되어 있으므로 수동 규칙 제거
- -renamesourcefileattribute는 Firebase 공식 문서 근거가 아니므로 제거
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant