ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
13.12k stars 1.07k forks source link

Support the server to run on Android API <=25 #1369

Open JajaComp opened 5 years ago

JajaComp commented 5 years ago

Ktor Version and Engine Used (client or server and name) io.ktor:ktor-server-netty:1.2.5

Describe the bug Ktor not work on Android API =< 25

To Reproduce When i try to create server i get error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication, PID: 5399
    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/ZoneId;
        at io.ktor.features.DefaultHeaders.<clinit>(DefaultHeaders.kt:70)

ZoneId was added in android just in API 26

cy6erGn0m commented 5 years ago

As a workaround, you could simply rewrite DefaultHeaders feature to avoid using java.time package.

cy6erGn0m commented 5 years ago

However, I would expect it to not work anyway since Netty may require a lot of API that doesn't fit.

dtmilano commented 5 years ago

I experienced a similar problem

uiAutomatorHelper(com.dtmilano.android.culebratester2.UiAutomatorHelper)
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Duration;
    at com.typesafe.config.impl.ConfigImpl.fromAnyRef(ConfigImpl.java:243)
    at com.typesafe.config.impl.ConfigImpl.fromPathMap(ConfigImpl.java:200)
    at com.typesafe.config.ConfigFactory.parseMap(ConfigFactory.java:1038)
    at io.ktor.server.engine.CommandLineKt.commandLineEnvironment(CommandLine.kt:32)
    at io.ktor.server.cio.EngineMain.main(EngineMain.kt:20)
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Duration" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.dtmilano.android.culebratester2.test-2/base.apk", zip file "/data/app/com.dtmilano.android.culebratester2-2/base.apk", zip file "/system/priv-app/MetricsApi/MetricsApi.apk", zip file "/system/priv-app/com.amazon.dp.logger/com.amazon.dp.logger.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 37 more
...

on Android API < 26, even though KtorApplication.kt does not include

  ...
  install(DefaultHeaders)
  ...

Other than that, it works perfectly well on Android API >= 26.

oleg-larshin commented 4 years ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.