测试室迁移.在assets文件夹中找不到架构文件



我的build.gradle文件,我使用的是kapt而不是java的注释处理器

defaultConfig {
...
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}

}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}

exportSchema设置为true的My RoomDatase基类


@Database(entities = [DB_Open::class],version = 4, exportSchema = true)

数据库方案get被导出并保存为json文件[1]:https://i.stack.imgur.com/r3Iew.png

但我的迁移测试仍然会出现此错误

java.io.FileNotFoundException: Cannot find the schema file in the assets folder. Make sure to include the exported json schemas in your test assert inputs. See https://developer.android.com/training/data-storage/room/migrating-db-versions#export-schema for details. Missing file: com.crop2cash.gather.data.GatherDatabase/1.json
at androidx.room.testing.MigrationTestHelper.loadSchema(MigrationTestHelper.java:320)
at androidx.room.testing.MigrationTestHelper.createDatabase(MigrationTestHelper.java:152)
at com.crop2cash.gather.MigrationsTest.migrate1to2(MigrationsTest.kt:29)
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.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
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 androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
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:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2189)

我已经尝试了这里的所有stackoverflow解决方案,如:

sourceSets {
getByName("debug").assets.srcDirs(files(projectDir, "schemas"))
}

sourceSets {

getByName("androidTest") {
assets.srcDirs(files(projectDir, "schemas"))
}
}

根据经验,这个问题的一个可能来源是在打包过程中剥离资产,即,如果您有类似以下规则的东西。它似乎只适用于发布版本,但遗憾的是,它也适用于调试,并将从视图中删除您的模式文件。

buildTypes {
debug {...}
release {
aaptOptions {
ignoreAssetsPattern '!*.json'
}
}
}

相关内容

  • 没有找到相关文章

最新更新