3

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

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

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

4

1 回答 1

2

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.")
    }
于 2017-06-20T15:20:06.733 回答