SNM
SNM

Reputation: 6805

NoSuchMethodException when obfuscating with proGuard

well, this is becoming a pain to generate my release apk and make it work

so, literally I build the apk succefully but I have an error whit a method

Caused by: java.lang.NoSuchMethodException: <init> [interface com.myapp.domain.login.LoginRepo]

Now, I have in my proGuard the followin

-keep class com.myapp.domain.** {*;}
-keep interface com.myapp.domain.** {*;}

Now, I dont know why this error is happening since I'm keeping these interfaces and this classes, the error line that told me about this problem is here

class LoginVMFactory(val repo:LoginRepo):ViewModelProvider.Factory {
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        return modelClass.getConstructor(LoginRepo::class.java).newInstance(repo)
    }
}

I also have this LoginVMFactory inside my domain package, so I'm also keeping this class, I really dont know why this is happening just before release, the app works well without proGuard but I dont want it to be 50mb, instead with proGuard it shrinks down to just 10

thanks

Upvotes: 3

Views: 828

Answers (1)

SNM
SNM

Reputation: 6805

The problem is that we need to also keep viewmodels when offuscating, so this line will keep all classes that extends from ViewModel

-keep public class * extends androidx.lifecycle.ViewModel {*;}

Upvotes: 1

Related Questions