Android room 兼容版本,Android Room 的坑

在添加依赖时,官网给出的是:

def room_version = "2.0.0-beta01"

implementation "androidx.room:room-runtime:$room_version"

annotationProcessor "androidx.room:room-compiler:$room_version" // use kapt for Kotlin

在使用以上的依赖,在编译时会报错,如下所示:

java.lang.RuntimeException: cannot find implementation for com.xx.xx.db.xxDatabase. xxDatabase_Impl does not exist

at androidx.room.Room.getGeneratedImplementation(Room.java:94)

at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:667)

at com.xx.xx.xx.xxDatabaseTest.getxxxxxDao(xxDatabaseTest.kt:14)

at java.lang.reflect.Method.invoke(Native Method)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.junit.runners.Suite.runChild(Suite.java:128)

at org.junit.runners.Suite.runChild(Suite.java:27)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at org.junit.runner.JUnitCore.run(JUnitCore.java:115)

at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)

at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:389)

at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)

解决方案:

在添加依赖时,修改为

implementation"androidx.room:room-runtime:$room_version"

//    annotationProcessor "androidx.room:room-compiler:$room_version"

kapt"androidx.room:room-compiler:$room_version"

你可能感兴趣的:(Android,room,兼容版本)