英文:
Kotlin AAR library w/ proguard: How to keep ONLY class and method names?
问题
我正在使用Kotlin构建一个Android库(aar文件)。我需要以一种方式混淆代码,使第三方用户能够看到类和方法名称,他们必须能够使用它们(它们是公开的),但我需要隐藏/混淆代码本身。
我尝试使用此文件作为myLibrary\proguard-rules.pro文件:
https://github.com/mohitrajput987/android-utility/blob/master/preference/proguard-rules.pro
但是,除了一个包含Kotlin和Java类的目录外,每个类、方法和变量都发生了变化,两个文件和目录名称保持不变。
如果这是我正在寻找的内容,那么Kotlin需要做哪些更改?
也许还有其他问题?
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '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
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
得分: 3
如果其他人也遇到这个问题,大多数情况下,这个方法应该能解决(不尝试混淆本机方法时):
-keepclasseswithmembernames class * {
public <methods>;
}
关于不同的keep
选项,可以在这里找到更多信息:Proguard保留规则
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论