使用 Realm 包含多个库时 DEX 失败

DEX failure when including multiple libs using Realm

我需要在我的项目中包含两个库,它们都定义了自己的 RealmObject。我不断收到以下错误: com.android.dex.DexException:多个dex文件定义Lio/realm/RealmJsonImpl;

当我从其中一个库中删除所有 RealmObject 时,一切正常。

这是关于领域预处理的吗?我有必要将这两个库与它们自己的 RealmObjects 一起使用。有可能吗?

Realm 在 0.81.1 之前不支持库项目。然而随着 0.81.1 发布了 RealmModules 允许你在库项目中使用 Realm。您可以在这里阅读更多内容:https://realm.io/news/realm-java-0.81.1/