라이브러리 빌드 기준

1. 인터페이스는 난독화 안함.

2. public 함수와 멤버는 난독화 안함.

3. 로컬 변수와 private함수는 난독화.


아래 설정 내용 중 붉은색 부분이 중요함.


[build.gradle]

apply plugin: 'com.android.library'

android {
    buildTypes {
        debug {
            minifyEnabled false
            useProguard false //https://developer.android.com/studio/build/shrink-code?hl=ko
            buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
}

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs = ["-parameters"]
    }
}



[proguard-rules.pro]

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\dev_tool\android_sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# 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 *;
#}

#Refer document
#https://developer.android.com/studio/build/shrink-code?hl=ko
#http://www.androidhuman.com/lecture/proguard/2016/07/23/proguard_for_library_project/
#https://gist.github.com/nisrulz/64dd09e0922aa48351c0
#https://www.guardsquare.com/en/proguard/manual/refcard
#https://www.guardsquare.com/en/proguard/manual/attributes
#https://www.guardsquare.com/en/proguard/manual/examples
#http://wiki.davepang.com/doku.php?id=develop:android:tips:use_proguard
#아래의 3가지 것들은 default 요소들이지만 중요한 option이라 설명한다.

#-dontobfuscate #없애면 난독화 X
#-dontoptimize #없애면 최적화 X
#-keepresourcexmlattributenames manifest/** #없애면 manifest 난독화 X
-dontshrink # 사용하지 않는 메소드 유지
-keepparameternames
#-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,MethodParameters,LocalVariableTable,LocalVariableTypeTable
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,MethodParameters
-keepattributes !LocalVariableTable,!LocalVariableTypeTable

-dontwarn android.support.v4.**,org.slf4j.**,com.google.android.gms.**
-dontskipnonpubliclibraryclasses


# com.ocsoosoo.lib의 하위 클래스를 전부 난독화하지 않음
#-keep class com.ocsoosoo.lib.**

# 모든 인터페이스를 전부 난독화하지 않음
#-keep interface * {
#  <methods>;
#  <fields>;
#}

# com.ocsoosoo.lib의 하위 인터페이스를 전부 난독화하지 않음
#-keep interface com.ocsoosoo.lib.**

# com.ocsoosoo.lib 하위 클래스 중 public static만 난독화하지 않음
-keep class com.ocsoosoo.lib.** {
    public static <fields>;
    public static <methods>;
    public <methods>;
    #public *;
}

-keepclassmembers class * {
    public static <fields>;
    #public *;
}

-keep interface com.ocsoosoo.lib.** { *; }

#빌드 후 mapping seed usage cofing 파일을 만들어주는 옵션
#-printmapping map.txt
#-printseeds seed.txt
#-printusage usage.txt
#-printconfiguration config.txt

#소스 파일의 라인을 섞지 않는 옵션 (이거 안해주면 나중에 stacktrace보고 어느 line에서 오류가 난 것인지 확인 불가)
#-keepattributes SourceFile,LineNumberTable

#소스 파일 변수 명 바꾸는 옵션
-renamesourcefileattribute SourceFile

#보통 라이브러리는 딱히 난독화 할 필요없을 때 이렇게 적어준다.
#-keep class 라이브러리패키지명.** { *; }

#워닝뜨는거 무시할때
-ignorewarnings
#지정해서 워닝 무시할 때
#-dontwarn 패키지명.**









+ Recent posts