Postmortem: ProGuard is annoying

This morning I received several crash reports from last night’s release.

I wasn’t able to replicate this crash on my debug environment. So this should be a production-only crash.

The first thing that came to my mind while I read the crash report is that this is a Proguard issue. The crash was happening in this class

import android.content.SharedPreferences
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
class OnlineJobsViewModelFactory(val sharedPreferences: SharedPreferences) : ViewModelProvider.Factory {
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        return modelClass.getConstructor(SharedPreferences::class.java).newInstance(sharedPreferences)
    }
}

The OnlineJobsViewModelFactory wasn’t able to find the interface android.content.SharedPreferences so it is throwing a

java.lang.NoSuchMethodException

So, I went to the Official Android Lifecycle documentation to find a Proguard rule for help but there was none. I had to dig the internet and found the rules on this GitHub Issue.

And eventually it was the fix that I needed.

I just wish the Android team would just include the Proguard rules in their documentation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

  You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

  You are commenting using your Google account. Log Out /  Change )

Twitter picture

  You are commenting using your Twitter account. Log Out /  Change )

  You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s