Ritesh
Ritesh

Reputation: 533

Realm Android : io.realm.exceptions.RealmException: 'DomainModel' doesn't exist in current schema

I am using realm db in android application I have integrated realm db as per documents which is as follows:

build.gradle(Project Level)

dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        classpath "io.realm:realm-gradle-plugin:3.7.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

build.gradle(App level)

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

following is code in MyApplication Class

Realm.init(this);
        RealmConfiguration config = new RealmConfiguration.Builder()
                .name(Realm.DEFAULT_REALM_NAME)
                .schemaVersion(1)
                .deleteRealmIfMigrationNeeded()
                .build();

        Realm.getInstance(config);
        Realm.setDefaultConfiguration(config);

Model Class

public class MyModel extends RealmObject {

    @PrimaryKey
    @SerializedName("message")
    private String message;

    @SerializedName("session_expired")
    private Integer sessionExpired;

    @SerializedName("domain_name")
    private String domainName;

    public String getDomainName() {
        return domainName;
    }

    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getSessionExpired() {
        return sessionExpired;
    }

    public void setSessionExpired(Integer sessionExpired) {
        this.sessionExpired = sessionExpired;
    }
}

Now, As far as debug build is concern, app is running as expected without any crash. But when I generate a release build, app get crash with

io.realm.exceptions.RealmException: 'MyModel' doesn't exist in current schema.

Please take a look at above code and please help me solve this crash. Thanks In advance.

Note: I am accessing a realm object as

Realm realm = Realm.getDefaultInstance();

following is the stacktrace

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   io.realm.exceptions.RealmException: 'MyModel' doesn't exist in current schema.
                                                                       at and.c(SourceFile:5112)
                                                                       at ans.a(SourceFile:48)
                                                                       at aon.a(SourceFile:68)
                                                                       at aop.d(SourceFile:285)
                                                                       at aop.a(SourceFile:178)
                                                                       at anb.a(SourceFile:3261)
                                                                       at abh.c(SourceFile:259)
                                                                       at com.mpose.com.mpose.activity.LoginActivity.k(SourceFile:306)
                                                                       at abh.b(SourceFile:1219)
                                                                       at com.mpose.com.mpose.activity.LoginActivity.loginClick(SourceFile:134)
                                                                       at com.mpose.com.mpose.activity.LoginActivity$$ViewBinder$1.doClick(SourceFile:18)
                                                                       at butterknife.internal.DebouncingOnClickListener.onClick(SourceFile:22)
                                                                       at android.view.View.performClick(View.java:4084)
                                                                       at android.view.View$PerformClick.run(View.java:16966)
                                                                       at android.os.Handler.handleCallback(Handler.java:615)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                       at android.os.Looper.loop(Looper.java:137)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                                       at java.lang.reflect.Method.invoke(Method.java:511)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                       at dalvik.system.NativeStart.main(Native Method)

Here Is how I am accessing MyModel class

final RealmQuery<MyModel> query = mRealm.where(MyModel.class).equalTo("message", "Success");
        RealmResults<MyModel> result = query.findAll();

        mRealm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                MyModel myModel = query.findFirst();
                if (myModel != null) {
                    myModel.setDomainName(strDomain);
                }
            }
        });

Upvotes: 1

Views: 959

Answers (1)

pandre
pandre

Reputation: 6725

Have you tried to update to the latest version? It's a nice idea to regularly check the Realm changelog for bugfixes.

I was having a similar issue and updating to Realm v3.7.2 solved it. In the changelog you can find:

Crash with "'xxx' doesn't exist in current schema." when ProGuard is enabled (#5211).

Upvotes: 1

Related Questions