问题
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