4

I'm using SafeArgs plugin and Navigation Architecture Component but the app is crashing.

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.package.domain.models.Model"

I'm using minifyEnabled true in the Gradle.

Also, I have three modules app, data, and domain. So, in all three proguard-rules files I have added

-keepnames class com.package.domain.models.Model1
-keepnames class com.package.domain.types.ImageType
-keepnames class com.package.domain.models.Model

I'm using these three classes as argType in my Navigation graph.

But the app is still crashing. Any help would be appreciated.

OhhhThatVarun
  • 3,431
  • 2
  • 21
  • 43

4 Answers4

6

I think the more appropriate thing to do would be adding this to add these in my proguard-rules file(s).

-keepnames class * extends android.os.Parcelable
-keepnames class * extends java.io.Serializable

As I don't have to keep annotating my models with @Keep which are Parcelable or Serializable or keeping the whole model package away from obfuscation.

Check this for more information.

OhhhThatVarun
  • 3,431
  • 2
  • 21
  • 43
2

Try with putting @Keep annotation top of class. Like

import androidx.annotation.Keep

@Keep
data class RepoData(val id: Long, val name: String)
NRUSINGHA MOHARANA
  • 1,323
  • 5
  • 11
0

You can keep the whole model package (it's usually alright to do it actually) like

-keep class com.package.domain.models.** { *; }
Amin
  • 2,816
  • 4
  • 20
  • 33
-1

Always use @keep annotation whenever you want the class to stay in memory .

@Keep data class MyData(val id: long,val name: String)