我想将我的应用重写为免安装应用。但是我在将 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
如何在功能模块中使用领域?
Realm 显式检查是否存在com.android.application
或com.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.")
}