mikepenz/storyblok-mp-SDK

Fatal Exception: java.lang.NoSuchMethodError

daliborristic883 opened this issue · 11 comments

About this issue

When my android app fetching stories, I am getting error as like below.

Fatal Exception: java.lang.NoSuchMethodError
No virtual method position(I)Ljava/nio/ByteBuffer; in class Ljava/nio/ByteBuffer; or its super classes (declaration of 'java.nio.ByteBuffer' appears in /system/framework/core-oj.jar)
  • Briefly describe the issue

  • How can the issue be reproduced / sample code
    This is sample codes.
    MainViewModel.kt

class MainViewModel : BaseViewModel() {

    val stories = MutableLiveData<List<Story>>()
private var storyblok = Storyblok(STORYBLOCK_TOKEN)

    init {
        viewModelScope.launch(Dispatchers.IO) {
            stories.postValue(storyblok.fetchStories())
        }
    }
}

MainViewActivity.kt

class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun observeViewModel() {
        viewModel.stories.observe(this) {
            for (story in it) {
                    Log.d("Story Log", story.fullSlug)
                }
        }
    }
}

Above error only showing on below Android 9. it is working well on Android 12.

Details

  •  Used library version: 1.2.1 (implementation("com.mikepenz:storyblok-mp-sdk-android:1.2.1"))
  •  Used platform: Sumsung Galaxy (Android 8)
  •  Used support library version
  •  Used gradle build tools version
  •  Used tooling / Android Studio version
  •  Other used libraries, potential conflicting libraries

Checklist

This is more detailed error logs.

java.lang.NoSuchMethodError: No virtual method position(I)Ljava/nio/ByteBuffer; in class Ljava/nio/ByteBuffer; or its super classes (declaration of 'java.nio.ByteBuffer' appears in /system/framework/core-oj.jar)
        at io.ktor.utils.io.bits.MemoryJvmKt.sliceSafe(MemoryJvm.kt:211)
        at io.ktor.utils.io.bits.Memory.slice-SK3TCg8(MemoryJvm.kt:47)
        at io.ktor.utils.io.charsets.CharsetJVMKt.encodeImpl(CharsetJVM.kt:356)
        at io.ktor.utils.io.charsets.EncodingKt.encodeToImpl(Encoding.kt:204)
        at io.ktor.utils.io.charsets.EncodingKt.encode(Encoding.kt:62)
        at io.ktor.utils.io.charsets.EncodingKt.encode$default(Encoding.kt:57)
        at io.ktor.http.CodecsKt.encodeURLParameter(Codecs.kt:123)
        at io.ktor.http.HttpUrlEncodedKt$formUrlEncodeTo$1.invoke(HttpUrlEncoded.kt:68)
        at io.ktor.http.HttpUrlEncodedKt$formUrlEncodeTo$1.invoke(HttpUrlEncoded.kt:67)
        at kotlin.text.StringsKt__AppendableKt.appendElement(Appendable.kt:85)
        at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:3347)
        at kotlin.collections.CollectionsKt___CollectionsKt.joinTo$default(_Collections.kt:3341)
        at io.ktor.http.HttpUrlEncodedKt.formUrlEncodeTo(HttpUrlEncoded.kt:67)
        at io.ktor.http.HttpUrlEncodedKt.formUrlEncodeTo(HttpUrlEncoded.kt:108)
        at io.ktor.http.HttpUrlEncodedKt.formUrlEncodeTo(HttpUrlEncoded.kt:94)
        at io.ktor.http.URLUtilsKt.appendUrlFullPath(URLUtils.kt:119)
        at io.ktor.http.URLBuilder.appendTo(URLBuilder.kt:79)
        at io.ktor.http.URLBuilder.buildString(URLBuilder.kt:93)
        at io.ktor.client.engine.android.AndroidClientEngine.execute(AndroidClientEngine.kt:45)
        at io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:85)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

@daliborristic883 which android tooling do you use?

  • build tools version
  • kotlin version
  • jvm version
  • ktor version

Seems like ktor is compiled to use an API which may not have been available in Android 9 :/

@mikepenz

  • build tools version: 4.2.1
  • kotlin version: 1.5.0
  • jvm version: 1.8
  • ktor version: 1.6.5

@mikepenz
Maybe this will be help for you.

Build dependencies showing as like screenshot.
build dependents

seems com.mikepenz:storyblok-mp-sdk-android:1.2.1 library using ktor v1.6.5 which not available to use on Android 9.

@daliborristic883 thank you for the additional details.

Maybe I'll need a sample app from you to reproduce this.

Just run https://github.com/mikepenz/storyblok-mp-SDK-blog on a APi 28 emulator (Android 9) and it won't crash.

Could you please have a look if these would help:

(kts)

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

That application uses Kotlin 1.6.10 and com.android.tools.build:gradle:7.0.4

So it could also be that the old Kotlin version causes this conflict, or the older gradle build tools don't properly backport Java 11 APIs (R8 should properly backport things for Java 8)

@mikepenz
Could you please give me your sample app source codes?
So I can compare it with my one.

It's the one linked here: #69 (comment)

It's a Kotlin Multiplatform app with an Android and Desktop portion.

It pulls the same data as I have on my blog: https://blog.mikepenz.dev/


The Android app part uses the most recent Android tech stack. Not sure if you have the chance to update to Kotlin 1.6? or a newer build tools version in your projecT?

Ok I will check and let you know result.
Thank you.

That application uses Kotlin 1.6.10 and com.android.tools.build:gradle:7.0.4

So it could also be that the old Kotlin version causes this conflict, or the older gradle build tools don't properly backport Java 11 APIs (R8 should properly backport things for Java 8)

After update Gradle version as like this, it is working. Thank you for your support.

Thank you very much, glad to hear this resolved it.

This link may be relevant for this topic: https://developer.android.com/studio/write/java8-support (same applies for Java 11 support which Android does handle too)