realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.46k stars 1.75k forks source link

Gradle build failed. #2890

Closed abdulgaffar291 closed 8 years ago

abdulgaffar291 commented 8 years ago

While trying to run this project, Gradle build failed.


> error: A RealmClass annotated object must implement RealmModel or derive from RealmObject
Note: Processing class NewCustomer
Note: Creating DefaultRealmModule

Version of Realm and tooling

Realm version(s): 1.0.0

Android Studio version: 2.1

Which Android version and device: Nexus 5

Zhuinden commented 8 years ago

Well, what's the NewCustomer class?

abdulgaffar291 commented 8 years ago

Its the realm model class which extends RealmObject.

beeender commented 8 years ago

@abdulgaffar291 Is it the full log? It supposed to have the problematic class name following error: A RealmClass annotated object must implement RealmModel or derive from RealmObject.

And also, are you using kotlin? Can you share the source code of the problematic class definition?

abdulgaffar291 commented 8 years ago
package com.realm;

import io.realm.RealmObject;
import io.realm.annotations.Required;

public class NewCustomer extends RealmObject {

    @Required
    private String name;

    private String cardNumber;
    private String mobileNumber;
    private String emailId;

    public void setName(String name){
        this.name = name;
    }

    public String getName(){
        return this.name;
    }

    public void setCardNumber(String cardNumber){
        this.cardNumber = cardNumber;
    }

    public String getCardNumber(){
        return this.cardNumber;
    }

    public void setMobileNumber(String mobileNumber){
        this.mobileNumber = mobileNumber;
    }

    public String getMobileNumber(){
        return this.mobileNumber;
    }

    public void setEmailId(String email){
        this.emailId = email;
    }

    public String getEmailId(){
        return this.emailId;
    }
}
abdulgaffar291 commented 8 years ago

@beeender No, i ain't using kotlin.

beeender commented 8 years ago

what is your android gradle plugin version? something in the root build.gradle Some thing like

classpath 'com.android.tools.build:gradle:2.1.0'
abdulgaffar291 commented 8 years ago

Yeah. absolutely @beeender

abdulgaffar291 commented 8 years ago

So, what would be the problem with gradle version 2.1.0

beeender commented 8 years ago

Then i have no idea why you have this problem ... Do you use instant run? Maybe try to clean the project and build again? If those doesn't solve the problem, you can share your project with us, we could have a look. send it to help@realm.io or any other way you want.

abdulgaffar291 commented 8 years ago

Ok i'll try to clean & rebuild it.

abdulgaffar291 commented 8 years ago

I've removed unwanted api's and i cleaned & rebuild it. then it got fixed

beeender commented 8 years ago

Great!

Hesamedin commented 8 years ago

I'm getting same error in logcat by using annotation.

@Parcel
@RealmClass
public class PointOfInterest {
    public static final int TYPE_NONE = 0;
    public static final int TYPE_RECENT = 1;
    public static final int TYPE_FAVORITE = 2;

    @PrimaryKey
    String uid;
    String poiServiceUuid;
    String address;
.
.
.

I cleaned and rebuilt project several times but I'm still getting same error message. However by removing that annotation and extending RealmObject, problem fixed. I thought annotation does the same thing extend does. I have no problem in my test project by using annotation but seems something is wrong in this project.

cmelchior commented 8 years ago

You also need to implements RealmModel pr https://realm.io/docs/java/latest/#realmmodel-interface