I am using reflection to read the name of the constructor's parameters. When I enable proguard (isMinifyEnabled = true
) the parameter name becomes arg0
, making my reflection fail. I have tried many proguard settings, as I show next.
This is my reflection code:
(this::class as KClass<Any>).let { thisClass ->
thisClass.firstConstructor.parameters.mapNotNull { parameter ->
parameter.name?.let { name ->
thisClass.memberProperties.firstOrNull { it.name == name }
}?.let { property ->
Argument.from(property, property.get(this), serializers)
}
}
}
The proguard setting that I expected to solve this issue:
-keep class * extends my.class.package.name.Destination {
public <init>(...);
}
I have also tried including public <fields>;
and public <methods>;
.
I have also tried these settings:
-keepparameternames
-keepattributes MethodParameters
-keepattributes Signature
Finally, I tried disabling shrinking with isShrinkResources = false
in gradle and disabling obfuscation with -dontobfuscate
in proguard, but it still renames my contructor's parameter to arg0
.
Relevant project versions: kotlin 1.8.0, android gradle 7.2.2, gradle 7.5.1, Android Studio Flamingo | 2022.2.1 Patch 1.
So, how can I keep the names of the constructor's parameters so that I can match them with memberProperties?
Aucun commentaire:
Enregistrer un commentaire