https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jiri Bruchanov

12/14/2019, 11:51 AM
Hi, is there any min versions requirement of jvm/android for ktor-server ? I'm having some issues with running latest version
1.3.0-beta-2
on android 4.4 and 5 and probably any other with jvm1.6, because of
Copy code
java.lang.NoSuchMethodError: No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File; or its super classes (declaration of '<http://java.io|java.io>.File' appears in /system/framework/core-libart.jar)
also with
1.3.0-beta-1
I'm getting following ktor-server-netty
Copy code
java.lang.NoClassDefFoundError: io.ktor.application.ApplicationEvents$subscribe$1
        at io.ktor.application.ApplicationEvents.subscribe(ApplicationEvents.kt:22)
        at io.ktor.server.engine.BaseApplicationEngine.<init>(BaseApplicationEngine.kt:31)
        at io.ktor.server.engine.BaseApplicationEngine.<init>(BaseApplicationEngine.kt:21)
        at io.ktor.server.netty.NettyApplicationEngine.<init>(NettyApplicationEngine.kt:27)
        at io.ktor.server.netty.Netty.create(Embedded.kt:14)
        at io.ktor.server.netty.Netty.create(Embedded.kt:12)
        at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:79)
        at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:67)
        at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:36)
        at io.ktor.server.engine.EmbeddedServerKt.embeddedServer$default(EmbeddedServer.kt:34)
        at com.scurab.android.anuitor.service.KtorServer.start(KtorServer.kt:50)
        ....
ktor-server-jetty
Copy code
MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
looks like if I avoid using anything what depends on
Path
in routing it works fine, which was just
Copy code
static { files(File(root)) }
in my case...
c

cy

12/14/2019, 12:07 PM
Is Path available from the beginning?
j

Jiri Bruchanov

12/14/2019, 12:08 PM
beginning of what ?
c

cy

12/14/2019, 12:09 PM
Android 😁
Perhaps we need to support Paths as well. This is my bad: we simply didn't try to make it work on Android at all
File should work
j

Jiri Bruchanov

12/14/2019, 12:14 PM
iirc java's Path is java1.7, so not really... Android Studio supports just most of syntax features, but not the API... this needs to be API26+ if I'm not mistaken to have full 1.7jvm
@cy is there some simple way to have ^^
static
in my case ? I wrote this
Copy code
fun Route.supportFiles(folder: File) {
    fun File?.combine(file: File) = when {
        this == null -> file
        else -> resolve(file)
    }
    val pathParameterName = "static-content-path-parameter"

    val dir = staticRootFolder.combine(folder)
    get("{$pathParameterName...}") {
        val relativePath = call.parameters.getAll(pathParameterName)?.joinToString(File.separator) ?: return@get
        val file = dir.combineSafe(relativePath)
        if (file.isFile) {
            call.respond(file.readBytes())
        }
    }
}
and then
Copy code
static { supportFiles(File(root)) }
which works fine, but it's just quick copy&paste of the ktor code with explicit file reading
35 Views