5

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,981
  • 2
  • 26
  • 49

4 Answers4

11

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,981
  • 2
  • 26
  • 49
  • Is there a reason why you use the "extends" qualifier instead of "implements"? Either way from what I found they should be equivalent I guess: https://www.guardsquare.com/manual/configuration/usage#classspecification – G00fY Sep 06 '22 at 19:18
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,489
  • 8
  • 13
0

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

-keep class com.package.domain.models.** { *; }
Amin
  • 3,056
  • 4
  • 23
  • 34
-1

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

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