문제
디버그 모드로 실행했을 때는 아무런 문제가 없었으나, 릴리즈 된 이후 마켓에서 다운로드해서 실행시켜보면 Retrofit2 에서 에러가 발생해 앱이 다운되는 현상이 발생한다.
해결
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod
# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
# Keep annotation default values (e.g., retrofit2.http.Field.encoded).
-keepattributes AnnotationDefault
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit
# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
# Keep inherited services.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface * extends <1>
# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep class com.mrhi.myapp.** { *; }
-keep class com.mrhi.myapp.model.** { *; }
-keep interface com.mrhi.myapp.network.** { *; }
난독화를 진행했기 때문에 발생했던 오류. 그래서 proguard-rules.pro 파일에 위와 같은 코드를 입력하여 Retrofit 에 관해서는 난독화를 진행하지 않겠다는 코드를 추가 삽입해준다. 단 마지막 세줄의 경우 내 앱과 관련한 부분이기 때문에 상황에 맞춰 바꿔주면 된다.
Retrofit 으로 불러들인 JSON 형식의 데이터가 난독화가 되기 때문에 그 부분을 방지해주는 코드이며, REST 코드 또한 프로가드 방지 코드를 설정해주어야 한다.