android - Android - Jetpack Compose - ResourceNotFoundException
问题描述
构建.gradle:
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.4-alpha03")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0-alpha03")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.1.0-alpha06")
我的 androidTest 类:
@get:Rule
val composeTestRule = createAndroidComposeRule(MainActivity::class.java)
@Test
fun testUI() {
composeTestRule.setContent {
AppTheme {
SomeComposeUI(
)
}
}
composeTestRule.activity.getString(R.string.apply)
InstrumentationRegistry.getInstrumentation().context.getString(R.string.apply)
}
我遇到的问题是composeTestRule.activity.getString(R.string.apply)
或者InstrumentationRegistry.getInstrumentation().context.getString(R.string.apply)
总是返回Method threw 'android.content.res.Resources$NotFoundException'
异常。
我尝试了最新的 alpha 版本和最新的稳定版本,但没有运气。我什至尝试过你可以在 android studio 中导入的 compose 项目,并且有同样的错误。
笔记:
- 使用 SDK 31 构建。
- 在 SDK 31 设备上进行测试(任何 SDK 设备都存在同样的问题)。
- AGP 7.0.2 - Gradle 7.2
任何帮助,将不胜感激
解决方案
composeTestRule.activity.getString(R.string.apply)
事实证明,在大多数情况下附加调试器时,我的项目和 android 项目无法使用。
在没有调试器的情况下运行不会有同样的问题,因此使开发变得更加困难,但至少我有一个修复。
推荐阅读
- c# - 使用 if 语句 c# 选择正确的列表
- r - R中的贬低/均值居中
- java - 从 Java 中的 Firebase 实时数据库中选择随机条目
- python-3.x - 使用 python 停止或嵌入命令提示符窗口
- asp.net-mvc - 在 ASP.NET MVC 中使用 DB 操作对控制器进行单元测试
- vim - 如何使用 Vim Tsuquyomi 插件和 :TsuDefinition 命令打开新窗口?
- spring - 如何在没有动态 Web 模块 3.0 方面黑客的情况下将 jdk 9 maven spring boot 2 项目导入 eclipse ee 氧气?
- eclipse - 构建非独立的 p2 存储库
- node.js - Windows上的多个版本的节点
- rdf - SPARQL 查询以提取人员的主语谓词和宾语