Kotlin AAR库与Proguard:如何仅保留类和方法名称?

huangapple go评论73阅读模式
英文:

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 &lt;methods&gt;; 
}

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

huangapple
  • 本文由 发表于 2020年1月6日 20:09:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611861.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定