I just call a method class through this line :
val instance = Class.forName(nameClass).kotlin.objectInstance
When I set the nameClass with a constant value (see below) it's work.
private const val PROVIDER_CLASS = "com.abc.xyz.feature.DynamicFeatureImpl\$Provider"
fun method() {
val instance = Class.forName(PROVIDER_CLASS).kotlin.objectInstance
}
But, when I set the nameClass to string (not constant), like this
fun method() {
val nameClass = "com.abc.xyz.feature.DynamicFeatureImpl\$Provider"
val instance = Class.forName(nameClass).kotlin.objectInstance
}
it's not work and throw java.lang.ClassNotFoundException.
I have trying make log, check is the value PROVIDER_CLASS are same with the string nameClass, and the result is true. but the code not work with string one. My goal is make the code work through variable className string as parameter.
So, what wrong with the code? it's make me confused.
Update: Actually it's call a method from dynamic feature with dagger. my reference this medium post
I solved this problem by adding rules to proguard-rules.pro on root project
-keep class com.abc.xyz.feature.DynamicFeatureImpl {
com.abc.xyz.feature.DynamicFeatureImpl$Provider Provider;
}
-keep class com.abc.xyz.feature.DynamicFeatureImpl$Provider {
*;
}
the rules that I've added before is only on consumer-rules (the dynamic module) but in fact it's not enough
-keep class com.abc.xyz.feature.** { *; }
-keep class com.abc.xyz.feature.di.** { *; }
It's make me confused a couple days, hope this will help somebody if find this issue.