after updating from room 2.2.6 to 2.3.0 I get an error: "You must annotate primary keys with @NonNull."
after updating from room 2.2.6 to 2.3.0 I get an error: "You must annotate primary keys with @NonNull."
我将房间从 2.2.6
更新为 2.3.0
,并在编译时开始在 compiled/generated java 代码中看到奇怪的错误。我在我的 .kt
文件或目录 ...build/tmp/kapt3/stubs/debug/...
中生成的 .java
文件中没有看到任何错误我只看到破坏构建的编译时错误。
我得到的完整错误:
error: You must annotate primary keys with @NonNull. "version" is nullable. SQLite considers this a bug and Room does not allow it. See SQLite docs for details: https://www.sqlite.org/lang_createtable.html
private java.lang.Integer version;
当我查看生成的 .java
代码时,我看到它正在对其进行注释:
@org.jetbrains.annotations.Nullable()
@androidx.annotation.NonNull()
private java.lang.Integer version;
我的 Kotlin 代码也有注释:
import androidx.annotation.NonNull
...
@NonNull
var version: Int? = null
我的代码运行良好,并且经过充分测试并证明可以使用房间 2.2.6
。我在更新房间 2.3.0
.
后才开始遇到这个问题
旧dependencies.gradle
implementation "androidx.room:room-runtime:2.2.6"
kapt "androidx.room:room-compiler:2.2.6"
已更新dependencies.gradle
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
感谢任何帮助!
Kotlin 不使用 @NonNull
注释 - 这是由您的类型本身决定的,在您的情况下是可为空的 Int?
.
您需要将其更改为 Int
并为其分配默认值(即 -1
)。
我将房间从 2.2.6
更新为 2.3.0
,并在编译时开始在 compiled/generated java 代码中看到奇怪的错误。我在我的 .kt
文件或目录 ...build/tmp/kapt3/stubs/debug/...
中生成的 .java
文件中没有看到任何错误我只看到破坏构建的编译时错误。
我得到的完整错误:
error: You must annotate primary keys with @NonNull. "version" is nullable. SQLite considers this a bug and Room does not allow it. See SQLite docs for details: https://www.sqlite.org/lang_createtable.html
private java.lang.Integer version;
当我查看生成的 .java
代码时,我看到它正在对其进行注释:
@org.jetbrains.annotations.Nullable()
@androidx.annotation.NonNull()
private java.lang.Integer version;
我的 Kotlin 代码也有注释:
import androidx.annotation.NonNull
...
@NonNull
var version: Int? = null
我的代码运行良好,并且经过充分测试并证明可以使用房间 2.2.6
。我在更新房间 2.3.0
.
旧dependencies.gradle
implementation "androidx.room:room-runtime:2.2.6"
kapt "androidx.room:room-compiler:2.2.6"
已更新dependencies.gradle
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
感谢任何帮助!
Kotlin 不使用 @NonNull
注释 - 这是由您的类型本身决定的,在您的情况下是可为空的 Int?
.
您需要将其更改为 Int
并为其分配默认值(即 -1
)。