Kotlin AAR library w/ proguard: How to keep ONLY class and method names?

早过忘川 提交于 2020-02-25 13:20:36

问题


I am building an android library (aar file) with Kotlin. I need to obfuscate the code in a way that the 3rd party user will see the class and method names, he must be able to use them (they are pubilc), but I need to hide/obfuscate the code itself. I tried using this file for the myLibrary\proguard-rules.pro file: https://github.com/mohitrajput987/android-utility/blob/master/preference/proguard-rules.pro

but every class, method and var is changed, except for a directory that has both a Kotlin and a Java class in it, both files and directory name remained the same.

If this is what I am looking for, what must be changed for Kotlin?

Perhaps something else is wrong?

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

}


回答1:


In case anyone else struggle with this issue, this should do the trick in most cases (when not trying to obfuscate native methods):

-keepclasseswithmembernames class * {
     public <methods>; 
}

More about different keep options can be found here: Proguard keep rules



来源:https://stackoverflow.com/questions/59611861/kotlin-aar-library-w-proguard-how-to-keep-only-class-and-method-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!