如何使用Realm与功能模块结构?

时间:2017-06-12 10:09:48

标签: android realm android-instant-apps

我想将我的应用程序重写为即时应用程序。但是我将Realm导入功能模块时遇到了一些问题。如果我写

apply plugin: 'com.android.feature' apply plugin:'realm-android'

在功能模块中,Gradle无法构建项目,错误是:

Error:(2, 0) The android or android-library plugin must be applied to the project

但是如果我把这个插件放到应用程序模块中,那么基本模块中的类就不能使用Realm。

apply plugin: 'com.android.application' apply plugin:'realm-android'

错误将是下一个: Error:(23, 16) error: package io.realm does not exist

如何在功能模块中使用领域?

1 个答案:

答案 0 :(得分:1)

Realm明确检查是否存在com.android.applicationcom.android.library个插件。由于它不知道com.android.feature插件,因此会收到异常。

https://github.com/realm/realm-java/blob/7dbacb438f8f1130155eacf06347fce703c8f1a8/gradle-plugin/src/main/groovy/io/realm/gradle/Realm.groovy#L34

void apply(Project project) {
    // Make sure the project is either an Android application or library
    def isAndroidApp = project.plugins.withType(AppPlugin)
    def isAndroidLib = project.plugins.withType(LibraryPlugin)
    if (!isAndroidApp && !isAndroidLib) {
        throw new GradleException("'com.android.application' or 'com.android.library' plugin required.")
    }
相关问题