带有proguard的Kotlin AAR库:如何仅保留类和方法名称? [英] Kotlin AAR library w/ proguard: How to keep ONLY class and method names?
问题描述
我正在用Kotlin构建一个android库(aar文件).我需要以一种使第三方用户看到类和方法名称的方式来混淆代码,他必须能够使用它们(它们是pubilc),但是我需要隐藏/混淆代码本身. 我尝试将此文件用于myLibrary \ proguard-rules.pro文件: https://github.com/mohitrajput987/android-实用程序/blob/master/preference/proguard-rules.pro
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
但是每个类,方法和var都会更改,除了其中既包含Kotlin类别又包含Java类的目录之外,文件和目录名称均保持不变.
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.
如果这是我要寻找的东西,那么Kotlin必须更改什么?
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'
}
}
}
推荐答案
万一其他人对此问题感到困惑,在大多数情况下(当不尝试混淆本机方法时),这应该可以解决问题:
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>;
}
有关不同的keep
选项的更多信息,请参见: Proguard保留规则
More about different keep
options can be found here: Proguard keep rules
这篇关于带有proguard的Kotlin AAR库:如何仅保留类和方法名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!