rybalkinsd / kohttp

Kotlin DSL http client
https://kohttp.gitbook.io
Apache License 2.0
478 stars 42 forks source link

java.lang.NoClassDefFoundError in API Level 23 (Android 6) #162

Closed sharafat closed 4 years ago

sharafat commented 4 years ago

I'm using Kohttp with AndroidAnnotations. For debug builds, I'm using MultiDex and for release builds, I'm disabling MultiDex and enabling ProGuard and Shrinking.

Everything is working fine on Android 8 and 9 devices. However, for Android 4.4 and 6 devices, I'm getting the following error when doing a post request:

java.lang.NoClassDefFoundError: io.github.rybalkinsd.kohttp.dsl.context.HeaderContext$sam$java_util_function_BiConsumer$0
        at io.github.rybalkinsd.kohttp.dsl.context.HeaderContext.forEach$kohttp(HeaderContext.kt:20)
        at io.github.rybalkinsd.kohttp.dsl.context.HttpContext.makeHeaders(HttpContext.kt:50)
        at io.github.rybalkinsd.kohttp.dsl.context.HttpContext.makeRequest(HttpContext.kt:38)
        at io.github.rybalkinsd.kohttp.dsl.HttpPostDslKt.httpPost(HttpPostDsl.kt:48)
        at com.eximusedu.app.service.Service.login(Service.kt:62)
        at com.eximusedu.app.LoginActivity.doLogin(LoginActivity.kt:137)
        at com.eximusedu.app.LoginActivity_.access$101(LoginActivity_.java:35)
        at com.eximusedu.app.LoginActivity_$5.execute(LoginActivity_.java:162)
        at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:400)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:833)

What could possibly the issue here? Thanks.

rybalkinsd commented 4 years ago

Hi @sharafat, thanks for submitting this issue. From the very first glance - it's a result of having jvmTarget=1.8 https://github.com/rybalkinsd/kohttp/blob/master/build.gradle.kts#L29

Probably, we can have separate build for 1.6

rybalkinsd commented 4 years ago

cc @IVSivak

sharafat commented 4 years ago

Hi @rybalkinsd, thanks for your reply. I'm already using Java 8 for compiling my android app:

android {
   compileOptions {
        targetCompatibility = "8"
        sourceCompatibility = "8"
    }
}

If specifying kotlinOptions.jvmTarget = "1.8" helps, then what's the syntax for including it in my build file? Or if including it doesn't help, is there any workaround I can use?

rybalkinsd commented 4 years ago

@sharafat is it possible to share your project somehow (either public/ or private repo)? or anything minimal where I can reproduce this bug?

sharafat commented 4 years ago

@rybalkinsd sure, thanks. I've added you to our private Bitbucket repository.

govorovsky commented 4 years ago

Hello. The issue is that the code in HeaderContext is calling Java 8 method Map.forEach()(which is unavailable on older Android versions) instead of Kotlin's Map.forEach. Details are here

rybalkinsd commented 4 years ago

Hi @govorovsky . Thanks for your PR!

rybalkinsd commented 4 years ago

fix will be available in 0.11.1