我正在尝试创建一个库RealmModule
,这样我就可以在我的服装和移动模块之间共享一个架构。我正在创建这样的模块
@RealmModule(library = true, allClasses = true)
public class ClimbingModule {
}
只有一个RealmObject
,我已将其放置在同一个库模块中并按如下方式创建:
public class Climb extends RealmObject {
private int grade;
private int type;
@Required private Date date;
@PrimaryKey private String id;
// getters and setters
...
}
它在此配置中使用:
RealmConfiguration config = new RealmConfiguration.Builder(context)
.deleteRealmIfMigrationNeeded()
.modules(new ClimbingModule())
.build();
Realm.setDefaultConfiguration(config);
我得到的错误是:
java.lang.RuntimeException: Unable to create application com.android.tools.fd.runtime.BootstrapApplication: io.realm.exceptions.RealmException: Could not find io.realm.ClimbingModuleMediator
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4715)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: io.realm.exceptions.RealmException: Could not find io.realm.ClimbingModuleMediator
at io.realm.RealmConfiguration.getModuleMediator(RealmConfiguration.java:293)
at io.realm.RealmConfiguration.createSchemaMediator(RealmConfiguration.java:267)
at io.realm.RealmConfiguration.<init>(RealmConfiguration.java:111)
at io.realm.RealmConfiguration.<init>(RealmConfiguration.java:63)
at io.realm.RealmConfiguration$Builder.build(RealmConfiguration.java:649)
at com.example.mysynclibrary.Shared.initRealm(Shared.java:34)
at com.example.grant.wearableclimbtracker.MyApplication.onCreate(MyApplication.java:20)
at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:370)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4712)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: io.realm.ClimbingModuleMediator
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at java.lang.Class.forName(Class.java:285)
at io.realm.RealmConfiguration.getModuleMediator(RealmConfiguration.java:288)
at io.realm.RealmConfiguration.createSchemaMediator(RealmConfiguration.java:267)
at io.realm.RealmConfiguration.<init>(RealmConfiguration.java:111)
at io.realm.RealmConfiguration.<init>(RealmConfiguration.java:63)
at io.realm.RealmConfiguration$Builder.build(RealmConfiguration.java:649)
at com.example.mysynclibrary.Shared.initRealm(Shared.java:34)
at com.example.grant.wearableclimbtracker.MyApplication.onCreate(MyApplication.java:20)
at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:370)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4712)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.ClimbingModuleMediator" on path: DexPathList[[dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-support-annotations-24.0.0_8ed1f58ead6d248c8a4f50bb1897cc60a8d93971-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-stetho-1.3.1_3739d2a1ecc8680bba36444b965da940ae04a19b-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-realm-annotations-1.1.0_6d467512d704956e369a7713fcd76becefc3e018-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-jsr305-2.0.1_fa7c5ea253e798c2471f648fc357192a6a638816-classes.dex", dex file "/data/data/com.example.grant.wearableclimbtracker/files/instant-run/dex/slice-io.realm-realm-android-library-1.1.0_99e6e7dc6894989e0af3ce27b39ee
io.realm.ClimbingModuleMediator应该在哪里创建?
我没有使用ProGuard或Multidex,这是我在SO上找到此错误的唯一罪魁祸首。
提前致谢!
答案 0 :(得分:0)
您应该禁用“即时运行”并可能执行干净重建。
答案 1 :(得分:0)
确保将插件应用到模块中
apply plugin: 'realm-android'
答案 2 :(得分:0)
在项目的.gradle文件中,
apply plugin: 'realm-android'
上面的行应该在Kotlin的行之后
apply plugin: 'kotlin-android'
或在JAVA中
apply plugin: 'com.android.library'