1. app 단위 gradle에서 minifyEnabled true 세팅

 

2. proguard-rules.pro 파일을 수정

외부 라이브러리 등의 난독화 설정을 해줘야한다.
라이브러리 docs에 proguard 관련 내용이 있으니 참고하면 된다.

또한 retrofit2와 rxjava 등을 사용한다면 통신에 필요한 모델들도 난독화에서 제외해야한다.

인텔리제이에서 아래와 같이 빨간줄이 뜨지만 정상작동한다.
(오히려 빨간줄을 없애려고 * 하나 줄이는 등의 작업을 하면 빌드 후 문제가 발생하는 듯 하다.)

 

3. 빌드 후 테스트하여 에러 등을 확인한다.

 

4. apktool / dex2jar / jd-gui 등의 디컴파일 툴 등을 이용하여 디컴파일해서 난독화가 잘되었는지 확인한다.

 

5. 기타

아래는 proguard-rules.pro파일을 수정할 때 필요한 코드 등을 정리한 것이다.
아래 내용에 없는 라이브러리는 해당 라이브러리 사이트나 docs에서 proguard 설정 코드를 찾아본다.
그래도 안된다면 구글링을 하여 선배님들이 만들어 놓은 코드를 사용하자.

더보기
# If you keep the line number information, uncomment this to
# hide the original source file name.
# 소스 파일 변수 명 바꾸는 옵션
-renamesourcefileattribute SourceFile

# Uncomment this to preserve the line number information for
# debugging stack traces.
# 소스 파일의 라인을 섞지 않는 옵션 (이거 안해주면 나중에 stacktrace보고 어느 line에서 오류가 난 것인지 확인 불가)
-keepattributes SourceFile,LineNumberTable

# 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

# 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>
# Retrofit2

# 카카오 지도 앱 (빨간줄 뜨지만 정상)
-keep class net.daum.** {*;}
-keep class android.opengl.** {*;}
-keep class com.kakao.util.maps.helper.** {*;}
-keepattributes Signature
-keepclassmembers class * {
    public static <fields>;
    public *;
}
# 카카오 지도 앱 (빨간줄 뜨지만 정상)

# 카카오 로그인
-keep class com.kakao.sdk.**.model.* { <fields>; }
-keep class * extends com.google.gson.TypeAdapter
# 카카오 로그인

# 네이버 로그인
-keep public class com.nhn.android.naverlogin.** {
       public protected *;
}
# 네이버 로그인

# firebase 구글 로그인
-keepattributes Signature
-keepattributes *Annotation*
# firebase 구글 로그인

# sqlite
-keep class org.sqlite.** { *; }
-keep class org.sqlite.database.** { *; }
-keep class net.sqlcipher.** { *; }
-dontwarn net.sqlcipher.**
# sqlite

# roomdb (androidx)
-keep class * extends androidx.room.RoomDatabase
-dontwarn androidx.room.paging.**
# roomdb

#glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
#glide


# okhttp3
-dontwarn okhttp3.**
-dontwarn okio.**
-dontnote okhttp3.**
# okhttp3


# support v4 ,v7
-dontwarn android.support.**
# support v4 ,v7


## gson (gson 컨버터와 다른 것)
###---------------Begin: proguard configuration for Gson  ----------
## Gson uses generic type information stored in a class file when working with fields. Proguard
## removes such information by default, so configure it to keep all of it.
#-keepattributes Signature
#
## For using GSON @Expose annotation
#-keepattributes *Annotation*
#
## Gson specific classes
#-dontwarn sun.misc.**
##-keep class com.google.gson.stream.** { *; }
#
## Application classes that will be serialized/deserialized over Gson
#-keep class com.google.gson.examples.android.model.** { *; }
#
## Prevent proguard from stripping interface information from TypeAdapterFactory,
## JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
#-keep class * implements com.google.gson.TypeAdapterFactory
#-keep class * implements com.google.gson.JsonSerializer
#-keep class * implements com.google.gson.JsonDeserializer
#
###---------------End: proguard configuration for Gson  ----------
## gson (gson 컨버터와 다른 것)

 

 

참고 사이트들

medium.com/ics-lab/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%95%B1-%EB%82%9C%EB%8F%85%ED%99%94-proguard-dexguard-%EB%A5%BC-%ED%95%B4%EB%B3%B4%EC%9E%90-1-%ED%94%84%EB%A1%9C%EA%B0%80%EB%93%9C-%ED%8E%B8-799999a43c4d

 

안드로이드 앱 난독화(Proguard & Dexguard)를 해보자! 1. 프로가드 편

Google play store에서 앱을 받아 apk 파일을 추출하는 어플을 사용하면 쉽게 apk을 얻을 수 있다.

medium.com

 

black-jin0427.tistory.com/89

 

[Android, Proguard] 안드로이드 프로가드 설정하기

안녕하세요. 블랙진입니다. 이번에는 코드 난독화 및 APK 최적화를 위한 프로가드에 대해 알아보겠습니다. Android Proguard 가 필요한 이유 1. 코드 난독화를 통해 디컴파일시 본인의 코드가 노출되

black-jin0427.tistory.com

 

namget.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-proguard-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0-retrofitgsonzxingglideokhttp3supportrxjava

 

안드로이드 proguard 적용하기 (retrofit,gson,zxing,glide,okhttp3,support,rxjava)

안녕하세요 남갯입니다 오늘은 안드로이드 proguard 적용 (난독화)하는 방법에대해 알려드리겠습니다. 일단 release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'progu..

namget.tistory.com

 

bigmatch.i-um.net/2016/08/05/retrofit2-rxjava-proguard-settings/

 

Retrofit2 + RxJava proguard 설정하기

안녕하세요, 이음소시어스에서 안드로이드 앱 개발을 맡고 있는 김범준(준) 입니다. 최근 안드로이드 HTTP Client 라이브러

bigmatch.i-um.net

 

developer88.tistory.com/118

 

ProGuard Rules 정리 (Retrofit & OkHttp, JSoup, GSon, RxJava, Glide etc)

다양한 라이브러리를 사용하는 만큼, 다양한 ProGuard를 사용해야 합니다. 그런데, 어떤 라이브러리는 이 부분에 대해서 명확히 정리하고 있고, 또 어떤 라이브러리는 그렇지 못합니다. 오늘은 제

developer88.tistory.com

 

gogorchg.tistory.com/entry/Android-Project%EC%97%90-Proguard-%EC%A0%81%EC%9A%A9-%ED%95%98%EA%B8%B0

 

[Android] Project에 Proguard 적용 하기

ProGuard를 적용하는 방법은 쉽습니다. build.gradle 파일 에 아래 소스만 넣어주면 땡입니다. buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'pro..

gogorchg.tistory.com

 

 

+ Recent posts