realm / realm-java

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

Realm.getDefaultInstance() causes crash if use realm in dependency library #4569

Closed leanh215 closed 7 years ago

leanh215 commented 7 years ago
  1. I build core-module which uses Realm 3.1.3 for data storage
  2. I upload core-module to my Nexus Repository Manager
  3. In my main project, I use core-module as a dependency. Add as dependency compile 'com.xxx:core.module:1.0.3'

Init in MyApplication

Realm.init(this); RealmConfiguration realmConfig = new RealmConfiguration.Builder() .deleteRealmIfMigrationNeeded() .modules(Realm.getDefaultModule(), new MyRealmCoreModule()) .build(); Realm.setDefaultConfiguration(realmConfig); Realm defaultInstance = Realm.getDefaultInstance();

  1. When I call Realm.getDefaultInstance(), it causes crash java.lang.AbstractMethodError: abstract method "io.realm.internal.ColumnInfo io.realm.internal.RealmProxyMediator.validateTable(java.lang.Class, io.realm.internal.SharedRealm, boolean)" at io.realm.Realm.initializeRealm(Realm.java:359) at io.realm.Realm.createAndValidate(Realm.java:317) at io.realm.Realm.createInstance(Realm.java:266) at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:145) at io.realm.Realm.getDefaultInstance(Realm.java:211) at com.mhealth.doctor.DoctorApplication.onCreate(DoctorApplication.java:95) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

  2. If I use core-module as a gradle module, It works like a charm Add to settings.gradle include ':core-module' project(':core-module').projectDir = new File(settingsDir, '../core-module/library') And add in app/build.gradle compile project(':core-module')

I don't know how to fix this issue. Please help

Zhuinden commented 7 years ago

Sounds like version mismatch to me.

leanh215 commented 7 years ago

I really have no idea with this issue =.=

kneth commented 7 years ago

@leanh215 Is it possible for you to share your project with us? You can do it privately by emailing help@realm.io.

leanh215 commented 7 years ago

We finally figured it out that in core-module, we built the .aar with old realm version (1.2.0). That's why we got crash. Thank you guys for helping us