Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep package-level kotlin functions in proguard?

I declared a package-level function as utility in my library and I want to use it in my main app.

My issue is that I am not able to keep it from code obfuscation using proguard (and consequently use it in my main app).

My file it.blabla.util.Extensions.kt

fun foo(context: Context, action: String) { ... } I already tried to keep it in proguard using:

-keep class it.blablabla.util.UtilPackage.** { *; }

or

-keep class it.blablabla.util.** { *; }

but none of these is working.

In my app I'm trying to use foo as follows:

foo(applicationContext, "test")

but I'm not able to find the right import to let foo become visible in my app through the aar module. I keep getting the following compilation error:

Unresolved reference: foo

like image 705
Manuela Avatar asked Nov 17 '22 00:11

Manuela


1 Answers

You most likely have to keep the the class as well as keeping the metadata (proguard doc):

-keep class it.blablabla.util.ExtensionsKt {
  *;
}
-keepkotlinmetadata
like image 60
mbonnin Avatar answered Mar 18 '23 17:03

mbonnin