fix: R8 난독화 시 Retrofit API 호출 실패 해결#383
Conversation
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 직접 사용이 없어져서 불필요
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 sharedJsonconfiguration.The same
Json { ignoreUnknownKeys = true }configuration is duplicated inResultCall.ktandResponseInterceptor.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
📒 Files selected for processing (4)
app/proguard-rules.proapp/src/main/java/com/runnect/runnect/data/network/calladapter/ResultCall.ktapp/src/main/java/com/runnect/runnect/data/network/calladapter/flow/FlowCallAdapter.ktapp/src/main/java/com/runnect/runnect/data/network/interceptor/ResponseInterceptor.kt
RetrofitV2/RetrofitFlow가 여전히 GsonConverterFactory를 사용하므로 DTO 필드명 난독화 방지 규칙이 필요. 이전 커밋에서 잘못 제거한 것을 복원.
작업 배경
R8 난독화 적용 후 릴리즈 빌드에서 모든 API 호출이 실패. 원인 2가지:
kotlin.Result(inline class)의 제네릭 타입 정보를 R8이 최적화 → Retrofit CallAdapter 생성 실패ResponseInterceptor등에서 Gson으로BaseResponse/ErrorResponse역직렬화 → R8 필드명 난독화로 매핑 실패변경 사항
ResponseInterceptor,ResultCall,FlowCallAdapter에서 Gson → kotlinx.serialization.json 전환proguard-rules.pro에-keep class kotlin.Result+-keepattributes Signature추가영향 범위
Test Plan
./gradlew assembleRelease빌드 성공🤖 Generated with Claude Code
Summary by CodeRabbit