为什么tor获取此错误父级的作业
我正在为Android客户端使用KTOR,但我有错误。 当我第一次运行该应用程序时,一切都很好,没有问题,但是当我单击设备返回按钮并关闭应用程序并再次打开应用程序时,该应用程序崩溃了,我会收到有关KTOR的错误:
父级完成
这是我的KTOR配置模块:
@InstallIn(SingletonComponent::class)
@Module
object NetworkModule {
private const val TIME_OUT = 60_000
@Singleton
@Provides
fun provideKtor(): HttpClient = HttpClient(Android) {
install(HttpCache)
defaultRequest {
contentType(ContentType.Application.Json)
accept(ContentType.Application.Json)
}
install(ContentNegotiation) {
json(json = Json {
prettyPrint = true
ignoreUnknownKeys = true
isLenient = true
encodeDefaults = false
})
}
install(HttpTimeout) {
connectTimeoutMillis = TIME_OUT.toLong()
socketTimeoutMillis = TIME_OUT.toLong()
requestTimeoutMillis = TIME_OUT.toLong()
}
install(ResponseObserver) {
onResponse { response ->
Log.d("HttpClientLogger - HTTP status", "${response.status.value}")
Log.d("HttpClientLogger - Response:", response.toString())
}
}
install(Logging) {
logger = object : Logger {
override fun log(message: String) {
Log.v("Logger Ktor =>", message)
}
}
level = LogLevel.NONE
}
}
}
Note: I use ktor version "2.0.2".
const val ktor_client_core = "io.ktor:ktor-client-core:$ktor_version"
const val ktor_client_cio = "io.ktor:ktor-client-cio:$ktor_version"
const val ktor_serialization_json = "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
const val ktor_serialization = "io.ktor:ktor-client-serialization:$ktor_version"
const val ktor_android = "io.ktor:ktor-client-android:$ktor_version"
const val ktor_negotiation = "io.ktor:ktor-client-content-negotiation:$ktor_version"
const val ktor_okhttp = "io.ktor:ktor-client-okhttp:$ktor_version"
const val ktor_logging = "io.ktor:ktor-client-logging:$ktor_version"
如何修复它?
I'm using ktor for the android client but I have an error.
When I run the app for the first time everything is fine and there is no issue, but when I click on the device back button and close the app, and open it again, the app is crashed and I get this error about the ktor:
Parent job is Completed
this is my ktor configure the module:
@InstallIn(SingletonComponent::class)
@Module
object NetworkModule {
private const val TIME_OUT = 60_000
@Singleton
@Provides
fun provideKtor(): HttpClient = HttpClient(Android) {
install(HttpCache)
defaultRequest {
contentType(ContentType.Application.Json)
accept(ContentType.Application.Json)
}
install(ContentNegotiation) {
json(json = Json {
prettyPrint = true
ignoreUnknownKeys = true
isLenient = true
encodeDefaults = false
})
}
install(HttpTimeout) {
connectTimeoutMillis = TIME_OUT.toLong()
socketTimeoutMillis = TIME_OUT.toLong()
requestTimeoutMillis = TIME_OUT.toLong()
}
install(ResponseObserver) {
onResponse { response ->
Log.d("HttpClientLogger - HTTP status", "${response.status.value}")
Log.d("HttpClientLogger - Response:", response.toString())
}
}
install(Logging) {
logger = object : Logger {
override fun log(message: String) {
Log.v("Logger Ktor =>", message)
}
}
level = LogLevel.NONE
}
}
}
Note: I use ktor version "2.0.2".
const val ktor_client_core = "io.ktor:ktor-client-core:$ktor_version"
const val ktor_client_cio = "io.ktor:ktor-client-cio:$ktor_version"
const val ktor_serialization_json = "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
const val ktor_serialization = "io.ktor:ktor-client-serialization:$ktor_version"
const val ktor_android = "io.ktor:ktor-client-android:$ktor_version"
const val ktor_negotiation = "io.ktor:ktor-client-content-negotiation:$ktor_version"
const val ktor_okhttp = "io.ktor:ktor-client-okhttp:$ktor_version"
const val ktor_logging = "io.ktor:ktor-client-logging:$ktor_version"
How can i fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现原因:这与
Hilt Di(NetworkModule)
有关。我现在必须使用一个对象而不是刀柄模块I found the reason: This is related to
Hilt Di (NetworkModule)
. I have to use an object instead of hilt module for now问题在于您不能使用HTTPClient的同一实例。
The problem is that you cannot use the same instance of the HttpClient.
尝试删除记录插件。我读了一些有关此信息的信息,这是由KTOR记录问题引起的
Try removing logging plugins. I was read some information about that, it caused by ktor logging issue