0

My app is working great on debug build variant, but when I put on release, that the only difference is the obfuscation, the app doesn't work well

 fun upsertPatient(patient: Patient, onCompletion: (Patient) -> Unit) {
        val px = PatSecHelper.patToN(patient, SecHelper.genKey())
        if (px != null) {
            val subscription = Single.fromCallable {
                val id = patientDao?.insertPatient(px)
                px.id = id
                px
            }
                    ?.subscribeOn(Schedulers.io())
                    ?.subscribe({
                        onCompletion(it!!)
                    }, {
                        BleLogHelper.writeError("Error inserting patient into database", it)
                    })
            subscriptions.add(subscription)
        }
    }

On debug mode works fine, but on release its raising a exception on this method above.

Unable to find generated Parcelable class for io.b4c.myapp.a.f, verify that your class is configured properly and that the Parcelable class io.b4c.myapp.a.f$$Parcelable is generated by Parceler.
Shermano
  • 1,100
  • 8
  • 31

2 Answers2

3

When minify is true then also proguard is used which rewrites names. To keep it in original version add it to proguard.cfg files, example:

-keep class com.example.Patient.** { *; }

You can also make it easier with following rule:

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

it makes all the classes implementing Parcelable, have their CREATOR fileds kept non obfuscated. See here: Do I need to 'keep' Parcelable in proguard rules while obfuscating

marcinj
  • 48,511
  • 9
  • 79
  • 100
3

Although the documentation says you have to put these lines to the Gradle:

compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'

change it to:

compile 'org.parceler:parceler-api:1.1.6'
kapt 'org.parceler:parceler:1.1.6'

Make sure all files you want to use are annotated with @Parcel.

I have class First with class Second variable and I forgot to annotate class Second. That's why changing from annotationProcessor to apt gives me a build error.

also, Don't forget to add -keep class com.example.Patient.** { *; } in your proguard file

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
GreenROBO
  • 4,725
  • 4
  • 23
  • 43
  • Thanks GreenROBO for helping me! do i have to put this rule for all my objects? whats the difference pron annotationProcessor to apt? – Shermano Jul 18 '19 at 15:31
  • @GreenTOBO, i mean, all my classes that implements Parcelable shoud have a rule like that? – Shermano Jul 18 '19 at 15:38
  • @Shermano see [marcinj's answer below](https://stackoverflow.com/a/57097940/1371792) – GreenROBO Jul 18 '19 at 15:44
  • @Shermano you can upvote & accept if it has helped you. So it will be helpful for others in the future. – GreenROBO Jul 18 '19 at 15:45
  • Yeah I did, I accepted @macninj answer tho sorry. Wish I could accept both, your answer was great as well – Shermano Jul 18 '19 at 17:06