[자바카페] 미니 세미나 proguard
DESCRIPTION
자바카페 미니세미나 발표 자료 입니다. Android ProGuard 최치환TRANSCRIPT
Android ProGuard2013.06.15
최치환
Content
ProGuard 에 대해 알아보기 .
ApiDemoe 에 ProGuard 를 적용하기 .
GSON 라이브러리 적용하기 .
ProGuard 란 ?
Shrunk
Optimize
Obfuscate
GPL 2.0
ProGuard 동작 방법
출처 : http://proguard.sourceforge.net/#manual/introduction.html
Input jars
Library jars
Shrunk OptimizeObfuscat
e
Library jars
Output jars
변화 없음
Shrunk
사용하지 않는 클래스 , 메소드 , 필드 제거
Optimize• Evaluate constant expressions.• Remove unnecessary field accesses and method calls.• Remove unnecessary branches.• Remove unnecessary comparisons and instanceof tests.• Remove unused code blocks.• Merge identical code blocks.• Reduce variable allocation.• Remove write-only fields and unused method parameters.• Inline constant fields, method parameters, and return values.• Inline methods that are short or only called once.• Simplify tail recursion calls.• Merge classes and interfaces.• Make methods private, static, and final when possible.• Make classes static and final when possible.• Replace interfaces that have single implementations.• Optionally remove logging code.
Obfuscate
class, method, field 수정
Ex) int count; => int a;
Reverse Engineer 로 인한 분석이 어렵다 .
코드의 크기가 줄어 든다 .
Obfuscate
[ProGuard 적용 전 ] [ProGuard 적용 후 ]
ProGuard 사용 결과
출처 : http://proguard.sourceforge.net/#results.html
ApiDemoe 에 ProGuard 를 적용하기 .
Android Sample Project 로 실습
ApiDemos 적용 결과 (1/2)
[ProGuard 를 적용하기 전 apk 파일 크기 ] [ProGuard 를 적용 후 apk 파일 크기 ]
ApiDemos 적용 결과 (2/2)
[ProGuard 를 적용하기 전 classes.dex 파일 크기 ]
[ProGuard 를 적용 후 classes.dex 파일 크기 ]
ProGuard 적용 결과 dump.txt
-> .apk 파일에 있는 모든 클래 파일의 구조를 설명
mapping.txt
-> 난독화 전과 난독화 후의 class, method, field 이름을 연결 시켜주는 파일
seeds.txt
-> 난독화가 되지 않는 class, method, field 목록
usage.txt
-> 제거된 코드들의 목록
Debug 방법mapping.txt
LogicSample1.java
GSON 라이브러리 적용하기 .
Json Parser library
Json -> Object
Gson gson = new Gson();
DataSample data = gson.fromJson(JSON_DATA, DataSample.class);
Object -> Json
Gson gson = new Gson();
String json = gson.toJson(sData);
GSON 라이브러리 적용하기 .
Json Data
{"address":" 서울시 ","phone":"010-1111-2222","name":" 홍길동 ","age":25}
MainActivity.java
DataSample.java
GSON 적용 결과
Debug Mode Release Mode
GSON 사용 방법 (1/2)
Annotation 사용
@SerializedName("name")
GSON 사용 방법 (2/2)
-keep public class