【问题标题】:Parceler - Unable to find generated Parcelable classParceler - 无法找到生成的 Parcelable 类
【发布时间】:2018-03-08 19:13:43
【问题描述】:

编辑

清理和重建后,不会生成类


我在尝试使用 Parcels.wrap() 时遇到此错误

Unable to find generated Parcelable class for xyz.xyz.models.reclamation.Reclamation, verify that your class is configured properly and that the Parcelable class xyz.xyz.models.reclamation.Reclamation$$Parcelable is generated by Parceler.

但是Reclamation$$Parcelable 类已创建,我可以看到它的内容。

那是我的毕业典礼:

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

尝试将 annotationProcessor 更改为 apt 会导致构建错误。

那是回收类

@Parcel
public class Reclamation {

public Reclamation() {
}

private int reclamationProductID;

private Integer preference;

private String takingDate1;

private String takingDate2;

private int takingAddressID;

private String takingAddressStreet;

private String takingAddressCity;

private String takingAddressZipCode;

private int type;

private String takingAddressCompany;
// + getters setters
}

这就是它崩溃的地方

ServiceStepFour_.builder().arg(Constants.ARG_RECLAMATION, Parcels.wrap(reclamation)).build();

我将它与 Android Annotations 结合使用。

有人知道为什么会这样吗?

【问题讨论】:

  • 你有没有机会在你的构建中配置了 proguard?

标签: android parceler


【解决方案1】:

虽然文档说你必须将这些行放到 gradle 中:

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

改成:

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

确保您要使用的所有文件都带有 @Parcel 注释。

我有一个带有 B 类变量的 A 类,但我忘了注释 B 类。这就是为什么从 annotationProcessor 更改为 apt 会导致构建错误。

【讨论】:

  • @JohnEricksen 很高兴见到你 :) 是的,我使用的是 apt 而不是 annotationProcessor
【解决方案2】:

就我而言,当我从 apt 移动到 annotationProcessor 时,我必须 删除这一行

apply plugin: 'com.neenbedankt.android-apt'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多