Skip to content

NoSuchMethodError в MainViewModel при импорте ядра на Android < 13 #32

Description

@cerdocyonina

при попытке импорта файла ядра падает с ошибкой java.lang.NoSuchMethodError. проблема вызвана использованием метода InputStream.readNBytes(int), который был добавлен в android api только с версии 13 (api 33), на устройствах с более ранними версиями этого метода нет в рантайме (протестировано на android 10, api 29, arm64-v8a)

стек:

java.lang.NoSuchMethodError: No virtual method readNBytes(I)[B in class Ljava/io/InputStream;
    at com.vkturn.proxy.viewmodel.MainViewModel$importKernel$2.invokeSuspend(MainViewModel.kt:376)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)

кланкер предлагает такое решение:

val bytes = context.contentResolver.openInputStream(uri)?.use { input ->
    val buffer = ByteArray(20)
    val read = input.read(buffer, 0, 20)
    if (read == -1) null else buffer.sliceArray(0 until read)
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions