Reputation: 123
Any help or guidance would be great; I've recently starting working with GreenDAO (version 3.1.1) using their new annotation processor rather than using the generation projects as the previous versions employed.
All goes well until I try to add custom constructors with class type parameters, or reference other class type functions within the class.
I am met with the following error:
Found 1 problem(s) parsing "C:\~\authentication\providers\AuthenticationToken.java":
Pb(83) AuthenticationProviderTypes cannot be resolved to a variable
:jroot:greendao FAILED
I'm using:
- GreenDAO 3.1.1
- Android Studio 2.1.3
- buildToolsVersion 23.0.3
- targetCompatibility JavaVersion.VERSION_1_7
- compileSdkVersion/targetSdkVersion 24
- minSdkVersion 19
What I've tried:
- 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.
Here's a shortened example of my entity class:
@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: I'm wondering if this problem is limitation or bug. I removed my custom constructor, created my class instance from the generated empty constructor and set my variable using the generated setter. It works, but goes against the point of having a concrete constructor in an object's logic. I feel this demonstrates the generator knows about and can resolve my AuthenticationProviderTypes class, just not at the constructor level.
Thanks again for any help or suggestions.
Upvotes: 0
Views: 491
Reputation: 17813
Let GreenDao generate its methods .. then implement serializable or parcelable.
Im deleting all generated methods, then call
./gradlew greendao
Upvotes: 1