Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'
    }
}

}

like image 227
Sharone Lev Avatar asked Sep 18 '25 13:09

Sharone Lev


1 Answers

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

like image 150
hardartcore Avatar answered Sep 21 '25 04:09

hardartcore