Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 启用proguard时,Kotlin与Timeout的协程不会引发TimeoutCancellationException_Android_Kotlin_Proguard_Kotlin Coroutines - Fatal编程技术网

Android 启用proguard时,Kotlin与Timeout的协程不会引发TimeoutCancellationException

Android 启用proguard时,Kotlin与Timeout的协程不会引发TimeoutCancellationException,android,kotlin,proguard,kotlin-coroutines,Android,Kotlin,Proguard,Kotlin Coroutines,当使用Timeout启用proguard时,似乎不会抛出TimeoutCancellationException 以下代码在不收缩或使用R8的情况下运行良好带超时按预期在3秒后触发超时取消异常 CoroutineScope(Dispatchers.Main + SupervisorJob()).launch { try { withTimeout(3000) { delay(400

当使用Timeout启用proguard时,似乎不会抛出TimeoutCancellationException

以下代码在不收缩或使用R8的情况下运行良好<代码>带超时按预期在3秒后触发超时取消异常

CoroutineScope(Dispatchers.Main + SupervisorJob()).launch {
                try {
                    withTimeout(3000) {
                      delay(4000)
                    }
                } catch (e: TimeoutCancellationException) {
                    Log.e(TAG, e.message)
                }
            }
但当我启用proguard时,将不再抛出异常,
delay
suspend函数将正常完成

我在proguard-rule.pro中使用以下规则:

-dontwarn kotlinx.coroutines.flow.**inlined**
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}

# Most of volatile fields are updated with AFU and should not be mangled
-keepclassmembernames class kotlinx.** {
    volatile <fields>;
}
任何人都经历过同样的问题?我是不是错过了一条前进的规则

谢谢

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'