java - 警告 : The following options were not recognized by any processor: '[room.schemaLocation]'

标签 java android android-studio android-gradle-plugin

我收到了这个警告:

警告:以下选项未被任何处理器识别:'[room.schemaLocation]'

我已经检查了以下链接的解决方案,这似乎是一个不同的问题。 我在 Android 项目上使用 Android Studio IDE 时收到错误。在更改 xml 中的绑定(bind)变量后弹出错误(由于拆箱警告,类型从 Integer 更改为 int,而我实际上只需要 int)。

已检查以下解决方案:

NetBeans bug 233098

getting-android-studio-gradle-and-android-annotations-working-together

annotationprocessor-option-not-recorgnized-by-any-processor

最佳答案

我在添加 room 的多模块项目中遇到了类似的问题。对于我的项目,问题是由于将我的 RoomDatabase 派生类添加到库模块,但配置了我的应用程序模块的 build.gradle

解决方案是配置包含RoomDatabase派生类的模块的build.gradle

解决方案有 3 个主要部分:

1. 您的 RoomDatabase 派生类(本例中为 AppDatabase)

@Database(entities = arrayOf(SomeWidgetEntity::class), version = 50)
abstract class AppDatabase : RoomDatabase() {
  //your code goes here
}

2. 在包含 AppDatabase 的模块的 build.gradle 文件中,将以下内容添加到 defaultConfig{}/ 部分。

defaultConfig {

    javaCompileOptions {
        annotationProcessorOptions {
        arguments = ["room.schemaLocation":
                     "$projectDir/schemas".toString()]
        }
    }

}

3.SAME build.gradle 文件的 dependencies{} 部分添加依赖项room 编译器。

dependencies {

    //for kotlin based projects (where $room_version is the version of room you're using)
    kapt "android.arch.persistence.room:compiler:$room_version"
    //for java based projects
    annotationProcessor "android.arch.persistence.room:compiler:$room_version"

}

关于java - 警告 : The following options were not recognized by any processor: '[room.schemaLocation]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45979736/

相关文章:

java - 我的 Activity 中的 onResume() 发生 Android 崩溃 - 为什么?

Java 使用 Joda 将 UTC 日期转换为本地日期

android - SeekBar setMin 在 Android 中至少需要 api 26?

android - 如何在 Android 中将日期时间从一种格式转换为另一种格式?

java - Android:启用检查按钮

java - 无效算法参数异常 : IV must be specified in CBC mode

android-studio - Android Studio : find in project explorer shortcut

java - 将 SNMP4J-Agent 与 Logback 配置结合使用

java - RMI 解码异常

android - 我怎样才能像这样设置 'EditText'的样式呢?