任何帮助或指导将是伟大的;我最近开始使用GreenDAO(版本3.1.1),使用他们新的注释处理器,而不是像以前的版本那样使用生成项目。
一切都很顺利,直到我尝试添加带有类类型参数的自定义构造函数,或者在类中引用其他类类型函数。
我遇到了以下错误:
Found 1 problem(s) parsing "C:~authenticationprovidersAuthenticationToken.java":
Pb(83) AuthenticationProviderTypes cannot be resolved to a variable
:jroot:greendao FAILED
我用:
- GreenDAO 3.1.1
- Android Studio 2.1.3
- buildToolsVersion 23.0.3
- targetCompatibility JavaVersion.VERSION_1_7
- compileSdkVersion/targetSdkVersion 24
- minSdkVersion 19
我试过了:
- Invalidate cache / restart android studio
- Clean build (like infinity times)
- Removing the custom constructor
- Does build, but defeats the point of needing constructor.
- Read through the documentation and added the @Keep annotation.
这是我的实体类的一个简短的例子:
@Entity(nameInDb = "authentication_token", active = true, createInDb = true)
public final class AuthenticationToken implements Serializable {
@Unique
@Id(autoincrement = false)
private Long id;
@SerializedName("InstanceAuthenticationType")
@Convert(converter = AuthenticationProviderTypes.AuthenticationProviderTypeConverter.class, columnType = Integer.class)
private AuthenticationProviderTypes authenticationType;
@SerializedName("CustomerCode")
@Convert(converter = CustomerCode.CustomerCodeConverter.class, columnType = String.class)
private CustomerCode customerCode;
@SerializedName("ContactCode")
@Convert(converter = ContactCode.ContactCodeConverter.class, columnType = String.class)
private ContactCode contactCode;
@SerializedName("PortalID")
private Integer portalID;
@Generated(hash = 1522783431)
public AuthenticationToken(Long id,
AuthenticationProviderTypes authenticationType,
CustomerCode customerCode,
ContactCode contactCode,
Integer portalID) {
// generated constructor code; this is fine, works & builds like a champ!
}
@Keep
public AuthenticationToken(AuthenticationProviderTypes preferredProviderType) {
// After successful build without this constructor
// I add this constructor to the entity class
// and it causes the GreenDAO generator / build to fail.
// without any other changes to the class or code
authenticationType = preferredProviderType;
}
}
UPDATE:我想知道这个问题是限制还是错误。我删除了自定义构造函数,从生成的空构造函数创建了类实例,并使用生成的setter设置了变量。它可以工作,但是违背了在对象逻辑中使用具体构造函数的观点。我觉得这说明生成器知道并能够解析我的AuthenticationProviderTypes类,只是不是在构造函数级别。
再次感谢任何帮助或建议。
让GreenDao生成它的方法。然后实现serializable或parcelable
删除所有生成的方法,然后调用
./gradlew greendao