Shermano
Shermano

Reputation: 1150

Why I'm facing Parcelable issues just when minify is true?

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.

Upvotes: 1

Views: 1591

Answers (2)

GreenROBO
GreenROBO

Reputation: 4910

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

Upvotes: 3

marcinj
marcinj

Reputation: 50026

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

Upvotes: 4

Related Questions