Hi
We usually use the create function to provide an instance of viewModel
viewModel { create<LoginViewModel>() }
when we turn on Proguard the function returns an error
Can't create definition for 'Factory [name='b',class='com.example.myApp.ui.login.imei.b']' due to error : No constructor found for class
To Reproduce
Steps to reproduce the behavior:
Koin version
org.koin:koin-androidx-viewmodel:1.0.2
Greetings
With that notation you are using reflection to instantiate your class. But since proguard cannot find any compile-time uses of your constructor, it gets remmoved. You need to write your own Proguard keep rules if you wish to use the reflection-based APIs.
we try to add different rules
-keepnames class android.arch.lifecycle.ViewModel
-keepclassmembers public class * extends android.arch.lifecycle.ViewModel {
public <init>(...);
}
-keepclassmembers class com.lebao.app.domain.** {
public <init>(...);
}
-keepclassmembers class * {
public <init>(...);
}
The last rule working correctly, allows the code to be obfuscated correctly and not deleted the constructors.
-keepclassmembers class * {
public <init>(...);
}
Thank you
You can probably declare it more explicit by
-keepclassmembers public class * extends androidx.lifecycle.ViewModel { public <init>(...); }
Your previous
-keepclassmembers public class * extends android.arch.lifecycle.ViewModel { public <init>(...); }
may not work because of old ViewModel package :)
Most helpful comment
we try to add different rules
-keepnames class android.arch.lifecycle.ViewModel -keepclassmembers public class * extends android.arch.lifecycle.ViewModel { public <init>(...); } -keepclassmembers class com.lebao.app.domain.** { public <init>(...); } -keepclassmembers class * { public <init>(...); }The last rule working correctly, allows the code to be obfuscated correctly and not deleted the constructors.
-keepclassmembers class * { public <init>(...); }Thank you