Как устранить ошибку «Канал безвозвратно испорчен и будет удален!»Android

Форум для тех, кто программирует под Android
Anonymous
Как устранить ошибку «Канал безвозвратно испорчен и будет удален!»

Сообщение Anonymous »

После нажатия кнопки я получаю следующие ошибки:

Канал необратимо поврежден и будет удален!

и

Не удалось открыть APK '/data/app...

и

не удалось добавить путь к ресурсу /data/app
Вот код из MainActivity:

Код: Выделить всё

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val tv = findViewById(R.id.tv)
val button = findViewById(R.id.button)

val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY

val client = OkHttpClient.Builder()
.addInterceptor(interceptor)
.build()

val retrofit = Retrofit.Builder()
.baseUrl("https://dummyjson.com")
.addConverterFactory(GsonConverterFactory.create())
.build()

val productApi = retrofit.create(ApiService::class.java)

button.setOnClickListener {
CoroutineScope(Dispatchers.IO).launch {
val product = productApi.getProductById()
runOnUiThread {
tv.text = product.title
}
}
}
}
}
ApiService:

Код: Выделить всё

interface ApiService {
@GET("products/1")
suspend fun getProductById(): Product
}
Продукт:

Код: Выделить всё

data class Product(
val id: Int,
val title: String,
val description: String,
val price: Int,
val discountPercentage: Float,
val rating: Int,
val stock: Float,
val brand: String,
val category: String,
val thumbnail: String,
val images: List,
)
Я пытался очистить и перестроить проект, сделать недействительными кэши и перезапустить, а также отключить оптимизацию MIUI в настройках телефона.

Подробнее здесь: https://stackoverflow.com/questions/784 ... e-disposed

Вернуться в «Android»