앱 축소와 난독화를 위해 shrinkResources true 와 minifyEnabled true 를 추가한다.
app.gradle
android {
..
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
..
}
이대로 앱을 release 모드에서 테스트 할 경우 몇 라이브러리에서 난독화로 인한 충돌이 생긴다.
때문에 해당 라이브러리에 대한 예외처리를 proguard-rules.pro 에 작성해 주어야 한다.
각 라이브러리마다 구글링을 통해 proguard 작성법을 알 수 있다.
retrofit의 경우 MyApi의 class와 interface, 그리고 enum을 각각 예외 처리한 코드를 추가했다.
그리고 소셜 로그인 시 access token 을 identityToken에 잘 넣어주지 않아 model, utils 패키지를 모두 예외처리 하였다.
proguard-rules-pro
# When minifyEnabled true
# retrofit
-keep class MyApi.models.* { *; }
-keep interface MyApi.apis.* { *; }
-keepclassmembers enum MyApi.models.* { *; }
# model, utils
-keep class com.myapp.model.** { *; }
-keep class com.myapp.utils.** { *; }
-keepclassmembers class com.myapp.model.** { *; }
-keepclassmembers class com.myapp.utils.** { *; }
-keepclassmembers enum * { *; }
# azure call
-keep class com.skype.rt.** {*;}
-keep class com.azure.** {*;}
-keep class com.skype.android.** {*;}
-keep class com.microsoft.media.** {*;}
-keep class com.microsoft.dl.** {*;}
# 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.*
#-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 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