【发布时间】:2019-11-01 18:15:01
【问题描述】:
这个问题是在我决定向房间数据库添加另一个实体之后出现的。架构正在导出到预期的目录中。所有 build.gradle 设置都已完成,似乎正在工作,但不是。自从我得到:
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.company.companyapp.db.AppStore/1.json
事实上,两个 json 模式都在生成,但测试运行程序无法找到此类文件。 这是gradle设置:
testOptions.unitTests.includeAndroidResources = true
defaultConfig {
...
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/store".toString()]
}
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
android.compileOptions.sourceCompatibility 1.8
android.compileOptions.targetCompatibility 1.8
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/store".toString())
}
dependencies {
def roomVersion = '2.2.1'
// Other deps ...
implementation "androidx.room:room-runtime:$roomVersion"
implementation "androidx.room:room-rxjava2:$roomVersion"
annotationProcessor "androidx.room:room-compiler:$roomVersion"
testImplementation "androidx.room:room-testing:$roomVersion"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation "androidx.test:core:$testCoreVersion"
androidTestImplementation "androidx.test.ext:junit:$extJUnitVersion"
testImplementation "androidx.test:core:$testCoreVersion"
testImplementation "androidx.test.ext:junit:$extJUnitVersion"
testImplementation "org.robolectric:robolectric:4.2.1"
}
我还注意到 Studio IDE 标记了 json 模式目录持有者
通过查看 google 房间迁移示例,我可以看出存在差异,而不是在谈论名称。
所以很明显 gradle 插件正在做一些不同于我想象的事情,或者文档说它应该可以工作,但它没有。
at androidx.room.testing.MigrationTestHelper.loadSchema(MigrationTestHelper.java:320)
at androidx.room.testing.MigrationTestHelper.createDatabase(MigrationTestHelper.java:152)
at com.company.companyapp.MigrationTest.migrate1To2(MigrationTest.java:32)
【问题讨论】:
-
我也遇到了同样的问题,你找到问题了吗?
标签: android android-room