Skip to content

fix: R8 난독화 시 Retrofit API 호출 실패 해결#383

Merged
unam98 merged 2 commits intorelease/v2.2.1from
bugfix/replace-gson-with-kotlinx
Apr 4, 2026
Merged

fix: R8 난독화 시 Retrofit API 호출 실패 해결#383
unam98 merged 2 commits intorelease/v2.2.1from
bugfix/replace-gson-with-kotlinx

Conversation

@unam98
Copy link
Copy Markdown
Collaborator

@unam98 unam98 commented Apr 4, 2026

작업 배경

R8 난독화 적용 후 릴리즈 빌드에서 모든 API 호출이 실패. 원인 2가지:

  1. kotlin.Result(inline class)의 제네릭 타입 정보를 R8이 최적화 → Retrofit CallAdapter 생성 실패
  2. ResponseInterceptor 등에서 Gson으로 BaseResponse/ErrorResponse 역직렬화 → R8 필드명 난독화로 매핑 실패

변경 사항

  • ResponseInterceptor, ResultCall, FlowCallAdapter에서 Gson → kotlinx.serialization.json 전환
  • proguard-rules.pro-keep class kotlin.Result + -keepattributes Signature 추가
  • Gson 직접 사용 제거로 DTO 필드 보존 ProGuard rule 불필요

영향 범위

  • 릴리즈 빌드의 모든 API 호출 / 에러 응답 파싱에 영향
  • Retrofit의 GsonConverterFactory 자체는 그대로 유지

Test Plan

  • ./gradlew assembleRelease 빌드 성공
  • 실 디바이스 릴리즈 APK — 방문자 모드 API 정상 응답 확인
  • 카카오/구글 로그인 후 API 정상 동작 확인
  • 에러 응답 파싱 정상 확인 (4xx/5xx)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal JSON parsing infrastructure for more reliable error handling and data processing.

1. ResponseInterceptor, ResultCall, FlowCallAdapter에서 Gson → kotlinx.serialization.json 전환
   - BaseResponse/ErrorResponse를 Gson으로 파싱하면 R8 난독화 시 필드명 매핑 실패
   - Kotlin Serialization은 컴파일 타임 코드 생성으로 난독화 영향 없음

2. kotlin.Result ProGuard 규칙 추가
   - R8이 inline class인 kotlin.Result의 제네릭 Signature를 최적화하면서
     Retrofit CallAdapter 생성 실패 (IllegalArgumentException)
   - square/retrofit#3880

3. DTO 필드 보존 규칙 제거
   - Gson 직접 사용이 없어져서 불필요
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 4, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6bcae819-a3c6-4d9c-9e61-cbf08e87ee71

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/replace-gson-with-kotlinx

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.

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

🧹 Nitpick comments (1)
app/src/main/java/com/runnect/runnect/data/network/calladapter/flow/FlowCallAdapter.kt (1)

22-22: Consider extracting shared Json configuration.

The same Json { ignoreUnknownKeys = true } configuration is duplicated in ResultCall.kt and ResponseInterceptor.kt. Consider extracting to a shared companion object or module-level constant to ensure consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@app/src/main/java/com/runnect/runnect/data/network/calladapter/flow/FlowCallAdapter.kt`
at line 22, Extract the duplicated Json configuration into a single shared
constant and replace the three local instances with that constant; specifically,
create a single Json instance (e.g., a module-level val or companion object
named JsonConfig or SHARED_JSON) and update the usages in FlowCallAdapter
(private val json), ResultCall, and ResponseInterceptor to reference that shared
symbol so they all use Json { ignoreUnknownKeys = true } from one place.
🤖 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/proguard-rules.pro`:
- Around line 14-19: Add a ProGuard/R8 keep rule to prevent obfuscation of
fields annotated with com.google.gson.annotations.SerializedName so
Retrofit+Gson can deserialize DTOs in release builds; update proguard-rules.pro
to keep class members annotated with `@SerializedName` (i.e., preserve fields with
the annotation) and ensure this rule coexists with the existing kotlin.Result
and Signature rules; alternatively, if you choose migration, replace
GsonConverterFactory usage and all `@SerializedName` annotations with
kotlinx.serialization `@SerialName` on the DTO classes and switch to
Json.asConverterFactory().

---

Nitpick comments:
In
`@app/src/main/java/com/runnect/runnect/data/network/calladapter/flow/FlowCallAdapter.kt`:
- Line 22: Extract the duplicated Json configuration into a single shared
constant and replace the three local instances with that constant; specifically,
create a single Json instance (e.g., a module-level val or companion object
named JsonConfig or SHARED_JSON) and update the usages in FlowCallAdapter
(private val json), ResultCall, and ResponseInterceptor to reference that shared
symbol so they all use Json { ignoreUnknownKeys = true } from one place.
🪄 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: 689b920e-2922-4752-96d1-ac25fc19af56

📥 Commits

Reviewing files that changed from the base of the PR and between 424db4c and e804944.

📒 Files selected for processing (4)
  • app/proguard-rules.pro
  • app/src/main/java/com/runnect/runnect/data/network/calladapter/ResultCall.kt
  • app/src/main/java/com/runnect/runnect/data/network/calladapter/flow/FlowCallAdapter.kt
  • app/src/main/java/com/runnect/runnect/data/network/interceptor/ResponseInterceptor.kt

Comment thread app/proguard-rules.pro
@unam98 unam98 self-assigned this Apr 4, 2026
RetrofitV2/RetrofitFlow가 여전히 GsonConverterFactory를 사용하므로
DTO 필드명 난독화 방지 규칙이 필요. 이전 커밋에서 잘못 제거한 것을 복원.
@unam98 unam98 merged commit fc720d5 into release/v2.2.1 Apr 4, 2026
1 check passed
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