Kotlin: Obfuscated Callable Expects 2 Arguments but 1 Provided (DefaultConstructorMarker Issue)

I’m encountering an issue in Kotlin when obfuscation is enabled, specifically when calling a function dynamically using KFunction.callBy. The code works fine in a non-obfuscated environment but fails once obfuscation is applied.

data class User(
    val name: String
)

private fun <T> buildObject(
    ...
    constructor: KFunction<T>,
): T {
    val params = constructor.valueParameters.mapIndexed { index, param ->
        val res = getValueForParam()
        param to res
    }.toMap()
    return constructor.callBy(params)
}

After enabling obfuscation, I receive the following error:

Callable expects 2 arguments, but 1 were provided.

It seems that constructor.caller.parameterTypes includes an additional parameter of type DefaultConstructorMarker.

proguard rules:

-keep class my.package.** { *;<init>(...); }
-keepclassmembers class my.package.**$* { *; }
-keepclassmembernames class my.package.**$* { *; }
-keep class kotlin.Metadata { *; }

Hi @Thomas_Constantin,

Can you try adding the following -keep rules:

# Keep Kotlin's default constructor markers
-keep class kotlin.jvm.internal.** { *; }

# Keep parameter names for reflection
-keepattributes *Annotation*, Signature, EnclosingMethod, InnerClasses, SourceFile, LineNumberTable, LocalVariableTable, LocalVariableTypeTable

Then clean your project, rebuild and test once more?

Thank you very much in advance.
Kind Regards,
Jack


1 Like

Hi,
thanks a lot for your support. Unfortunately it’s not working