Koin: Proguard with ViewModel

Created on 9 Apr 2019  路  2Comments  路  Source: InsertKoinIO/koin

Description
I'm using androidX viewmodel. everything works fine when proguard is disabled but when i enable proguard it gives me this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{io.omido.tabrizonline/io.omido.tabrizonline.ui.splashscreen.SplashScreenActivity}: i.a.e.a: Can't create definition for 'Factory [name='d',class='d.a.a.h.l.d', binds~(androidx.lifecycle.ViewModel)]' due to error :
            No constructor found for class 'class d.a.a.h.l.d'

and at last it points to line 25 that is my viewmodel:
io.omido.tabrizonline.ui.splashscreen.SplashScreenActivity.onCreate(:25)

To Reproduce
Steps to reproduce the behavior:

  1. add module
val appModule = module {
    viewModel<SplashScreenViewModel>()
}
  1. inject viewmodel
    private val viewModel by viewModel<SplashScreenViewModel>()
  2. Turn on proguard
  3. See error

Koin project used and used version (please complete the following information):

implementation 'org.koin:koin-android:1.0.2'
implementation 'org.koin:koin-androidx-scope:1.0.2'
implementation 'org.koin:koin-androidx-viewmodel:1.0.2'
question

Most helpful comment

You are using the experimental reflection-based API from Koin 1. Therefor there is no hard reference to your viewmodel's constructor and Proguard removed it. You should write a keep rule for your view models or - my advise - not use the reflection based API.

All 2 comments

You are using the experimental reflection-based API from Koin 1. Therefor there is no hard reference to your viewmodel's constructor and Proguard removed it. You should write a keep rule for your view models or - my advise - not use the reflection based API.

avoid using the api builder which is based on reflection.

Was this page helpful?
0 / 5 - 0 ratings