Android 为什么我';当minify为真时,我面临包裹问题?

Android 为什么我';当minify为真时,我面临包裹问题?,android,proguard,parcelable,Android,Proguard,Parcelable,我的应用程序在调试构建变量上运行得很好,但当我发布时,唯一的区别是混淆,应用程序运行得不好 fun upsertPatient(patient: Patient, onCompletion: (Patient) -> Unit) { val px = PatSecHelper.patToN(patient, SecHelper.genKey()) if (px != null) { val subscription = Single

我的应用程序在调试构建变量上运行得很好,但当我发布时,唯一的区别是混淆,应用程序运行得不好

 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调试模式工作正常,但在发布时,它会引发上述方法的异常

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.

当minify为true时,还将使用proguard重写名称。要保持原始版本,请将其添加到proguard.cfg文件中,例如:

-keep class com.example.Patient.** { *; }
您还可以使用以下规则简化此操作:

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

它使所有实现Parcelable的类都可以使用,并使其创建者文件保持不模糊。请参见此处:

尽管文档中说您必须将这些行放在渐变中:

compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'
将其更改为:

compile 'org.parceler:parceler-api:1.1.6'
kapt 'org.parceler:parceler:1.1.6'
确保要使用的所有文件都用@Parcel注释

我有class
First
和class
Second
变量,我忘了注释class
Second
。这就是为什么从annotationProcessor更改为apt会导致生成错误


另外,别忘了在您的proguard文件中添加
-keep class com.example.Patient.*{*;}

谢谢GreenROBO的帮助!我必须为我的所有对象设置此规则吗?annotationProcessor与apt有什么区别?@GreenTOBO,我的意思是,我所有实现Parcelable的类都应该有这样的规则?@Shermano请看@Shermano如果它对你有帮助,你可以投票并接受它。所以这对将来的其他人来说是有帮助的。是的,我接受了@macninj的回答,但很抱歉。希望我能接受这两个,你的回答也很好谢谢marcinj帮助我!我必须把这条规则用于我所有的物品吗?哦,很好,我真的很感谢你的帮助,谢谢你!!