小编tak*_*rsh的帖子

Kotlin 协程单元测试失败,并显示“带有主调度程序的模块初始化失败”

为使用withContext(Dispatchers.Main)测试方法的kotlin 挂起方法运行单元测试时失败,出现以下异常:

我的协程库版本是kotlinx-coroutines-core:1.1.1kotlinx-coroutines-android:1.1.1

例子:

suspend fun methodToTest() {
        withContext(Dispatchers.Main) {
           doSomethingOnMainThread()
                val data = withContext(Dispatchers.IO) {
                    doSomethingOnIOThread()
                }
        }
    }
Run Code Online (Sandbox Code Playgroud)

此外,当我删除withContext(Dispatchers.Main)它时,它工作正常。

java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used

at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing(MainDispatchers.kt:79)
at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MainDispatchers.kt:54)
at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:373)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:152)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

unit-testing kotlin kotlin-coroutines

14
推荐指数
5
解决办法
9459
查看次数

带有谷歌助手的应用程序操作测试工具显示“抱歉,我找不到它”

我在使用应用程序操作测试工具运行应用程序操作健身示例时遇到此问题,助手说“抱歉,我找不到”

步骤如下:

  1. 以草稿模式上传 APK 至 Play 商店内部测试曲目
  2. 使用同一帐户登录(设备、PlayConsole 和 AndroidStudio)
  3. 将packageId更改为我已上传到 Playstore 的应用程序
  4. 运行应用程序操作测试工具 ->预览上传成功
  5. 运行-> 在设备中打开助手,并显示消息“抱歉,找不到该内容”

android google-assistant-sdk app-actions

5
推荐指数
2
解决办法
2960
查看次数

Material Design 3 如何禁用高程叠加?

Android Material 3引入了海拔覆盖(色调颜色覆盖)。如果提供或增加,则会导致 MaterialCard 视图的背景颜色发生变化android:elevation,并影响原始背景颜色。

  1. 如何设置材质 3 立面叠加层的样式?
  2. 如果向视图提供了标高,如何禁用材质 3 标高叠加以避免卡片视图的背景颜色更改。

文档没有提供太多与样式或禁用高程覆盖相关的信息。

https://developer.android.com/jetpack/compose/designsystems/material3#elevation https://m3.material.io/styles/elevation/applying-elevation

android material-design material-components-android android-dark-theme material-design-3

4
推荐指数
1
解决办法
2773
查看次数