我们已准备好用realm发布我们的第一个应用程序, oops ,最后尝试了一个发布版本。一切正常,直到我们启用proguard,然后应用程序在启动时崩溃:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.activities.IntroActivity}: io.realm.exceptions.RealmException: Could not find io.realm.RealmHelper$ManifestModuleMediator
...
Caused by: io.realm.exceptions.RealmException: Could not find io.realm.RealmHelper$ManifestModuleMediator
at io.realm.y.a(Unknown Source)
at io.realm.y.a(Unknown Source)
at io.realm.y.<init>(Unknown Source)
at io.realm.y.<init>(Unknown Source)
at io.realm.z.a(Unknown Source)
at com.example.realm.RealmHelper.a(Unknown Source)
at com.example.activities.IntroActivity.onCreate(Unknown Source)
我们正在使用领域推荐的proguard设置,即:
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }
-dontwarn javax.**
-dontwarn io.realm.**
有什么建议吗?不幸的是我们没有任何proguard向导...
FWIW,我尝试将此行添加到proguard配置中:
-keep class io.realm.** { *; }
这改变了跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.activities.IntroActivity}: io.realm.exceptions.RealmException: Could not find io.realm.RealmHelper$ManifestModuleMediator
...
Caused by: io.realm.exceptions.RealmException: Could not find io.realm.RealmHelper$ManifestModuleMediator
at io.realm.RealmConfiguration.getModuleMediator(Unknown Source)
at io.realm.RealmConfiguration.createSchemaMediator(Unknown Source)
at io.realm.RealmConfiguration.<init>(Unknown Source)
at io.realm.RealmConfiguration.<init>(Unknown Source)
at io.realm.RealmConfiguration$Builder.build(Unknown Source)
at com.example.realm.RealmHelper.a(Unknown Source)
at com.example.activities.IntroActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6251)
不确定这是否有帮助...
答案 0 :(得分:0)
我们能够通过将两个@RealmModule类拆分成单独的文件来解决这个问题。即我们从:
RealmHelper.java
@RealmModule(classes = {Publisher.class, Puzzle.class, Volume.class, VolumeSet.class})
public static class ManifestModule {
}
@RealmModule(classes = {PuzzleMove.class, PuzzleState.class, VolumeState.class})
public static class PuzzleStateModule {
}
以强>:
境界/模块/ ManifestModule.java
@RealmModule(classes = {Publisher.class, Puzzle.class, Volume.class, VolumeSet.class})
public class ManifestModule {
}
和 realm / modules / PuzzleStateModule.java
@RealmModule(classes = {PuzzleMove.class, PuzzleState.class, VolumeState.class})
public class PuzzleStateModule {
}
RealmHelper.java
import com.example.realm.modules.ManifestModule;
import com.example.realm.modules.PuzzleStateModule
我不确定一个文件在两个文件中运行正常没有发生什么魔法,以及为什么Proguard以某种方式推动它,但它似乎再次起作用了!