2026/03/03

오늘의 이야기

 


https://billcorea.tistory.com/198



 


안드로이드 앱 만들기 : 코드 난독화, 축소의 폐해(?)


https://developer.android.com/studio/build/shrink-code.html?hl=ko#kts 앱 축소, 난독화 및 최적화  | Android 개발자  | Android Developers 사용하지 않는 코드와 리소스를 삭제하기 위해 출시 빌드에서 코..


billcorea.tistory.com




 


이전에 posting 했던 글처럼, 코드 난독화를 설정하고 릴리즈를 했을 때 발생했던 상황이 정리가 되어, 그 정리 방안을 기록해 두어야겠다.


 


먼저 gradle 파일에 코드 난독화 설정 하기에 예외 처리 등록하는 방법은 다음과 같이 설정하면 된다. 


 


gradle 파일의 설정


buildTypes {
debug {
buildConfigField "Boolean", "DEBUG_MODE", "true"
}
release {
buildConfigField "Boolean", "DEBUG_MODE", "false"
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

빌드 타입에 따라서 debug 모드에서는 빌드 되는 시간을 절약하기 위해서 설정을 넣지 않았고, release 모드에서 설정이 되도록 추가하였다.  


 


다음은 proguade-rules.pro 파일에 설정을 추가 하였다. 


# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# Add this global rule
-keepattributes Signature

# This rule will properly ProGuard all the model classes in
# the package com.yourcompany.models.
# Modify this rule to fit the structure of your app.
-keep public class com.bill...........databean.** { *; }

-keep public class 뒤에 따라오는 건 내 project 의 package 이름의 경로라고 보면 된다.  databean 아래에 있는 모든 class는 난독화를 하지 않겠다고 하는 것이다. 


 


데이터 저장된 예시



 


코드 난독화가 된 이후에도 database 구조는 구현된 이름 그대로 저장 되어 있는 것을 볼 수 있었다.   이것으로 난독화를 했을 때 야기될 수 있는 문제점에 대한 이해와 그 해결에 대한 정리를 마무리해 두어야겠다.


 





댓글 없음:

댓글 쓰기

오늘의 이야기

  청사옆 숲길 점심을 먹고 나서면 이제 제법 낮볓이 뜨겁다.  청사가 가까이에 있어 주변에 조성된 숲길(?)이 이제 제법 시원하게 느껴 지기도 한다. 점심을 먹고 나면 잠깐 낮잠이 오히려 필요한 것 같은 요즘이기는 하나, 갈수록 무거워지는 몸을 지탱...