chk
02/11/2020, 5:39 AMFatal Exception: java.lang.ExceptionInInitializerError
Caused by java.lang.ClassNotFoundException: my.package.InvestmentFeatureImpl$Provider
Caused by java.lang.ClassNotFoundException: Didn't find class "my.package.InvestmentFeatureImpl$Provider" on path: DexPathList[[zip file "/data/app/com.lenddo.mobile.paylater-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
The format we are using is app-bundles (.aab
) (dynamic delivery). The class not found is in a feature module, so we are trying to call a method in that feature module from the core module - using reflection (Kotlin) - Approach 1 (https://medium.com/androiddevelopers/patterns-for-accessing-code-from-dynamic-feature-modules-7e5dca6f9123)
It works well for some devices/users but doesn't for others in production.
I have set proguard
rules for the class/interface already but still doesn't work
object InvestmentFeature {
private const val PROVIDER_CLASS = "$PACKAGE_NAME.InvestmentFeatureImpl\$Provider"
val investmentModuleProvider = Class.forName(PROVIDER_CLASS).kotlin.objectInstance as InvestmentFeature.Provider
}
class DashboardViewModel constructor(activity: AppCompatActivity) : ViewModel() {
var investmentModule: InvestmentFeature? = null
var investmentProductsLiveData: LiveData<List<InvestmentProductEntity>>? = null
init {
// ExceptionInInitializerError is thrown here
investmentModule = investmentModuleProvider.get()
investmentProductsLiveData = investmentModule!!.getInvestmentProducts()
}
This is inside app
module:
interface InvestmentFeature {
fun getInvestmentProducts(): LiveData<List<InvestmentProductEntity>>
interface Provider {
fun get(): InvestmentFeature
}
}
This is inside my feature module - investment
class InvestmentFeatureImpl : InvestmentFeature {
override fun getInvestmentProducts(): LiveData<List<InvestmentProductEntity>> {
val repository = Repository.INSTANCE
return repository.getInvestmentProductsLiveData()
}
/**
* The provider singleton. It is accessed from the base app ViewModel through reflection.
*/
companion object Provider : InvestmentFeature.Provider {
override fun get(): InvestmentFeature {
return InvestmentFeatureImpl()
}
}
}
Please I need help on this.