question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ktor HTTP Server on Android 5.0 (API 21) leads to an error

See original GitHub issue

Running the Ktor embedded HTTP Server in an Android app on a real Android 5.0 device (Lenovo Tab3 Essential 7) or in the Emulator leads to exactly the error described already at stackoverflow by someone else. When running the same app out of Android Studio in the Emulator with Android 7, it is working well without an error.

The basic code that leads to the error: val server = embeddedServer(Netty, port = 8080) { routing { get("/") { call.respondText("Hello World!", ContentType.Text.Plain) } } }

The Error / Stacktrace: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.tabelos.tabelos, PID: 4028 java.lang.NoClassDefFoundError: io.ktor.application.ApplicationEvents$subscribe$1 at io.ktor.application.ApplicationEvents.subscribe(ApplicationEvents.kt:18) at io.ktor.server.engine.BaseApplicationEngine.<init>(BaseApplicationEngine.kt:29) at io.ktor.server.engine.BaseApplicationEngine.<init>(BaseApplicationEngine.kt:15) at io.ktor.server.netty.NettyApplicationEngine.<init>(NettyApplicationEngine.kt:17) at io.ktor.server.netty.Netty.create(Embedded.kt:10) at io.ktor.server.netty.Netty.create(Embedded.kt:8) at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:50) at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:40) at io.ktor.server.engine.EmbeddedServerKt.embeddedServer$default(EmbeddedServer.kt:27) at com.tabelos.tabelos.MainActivity.runServer(MainActivity.kt:48) at com.tabelos.tabelos.MainActivity.access$runServer(MainActivity.kt:21) at com.tabelos.tabelos.MainActivity$runnable$1.run(MainActivity.kt:43) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

I would welcome any help or advice, because I definitely need to target Android 5.0 because of the mentioned Lenovo Tab 3 Essential 7 Tablets, I’m using. I already tried downgrading kotlin, ktor versions without any luck so far.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
dkrivoruchkocommented, Mar 23, 2020

Looks like AGP 4.0 will desugar it https://developer.android.com/studio/preview/features#j8-desugar so it should work

0reactions
gnareacommented, May 5, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Attempting to run an embedded Ktor HTTP Server on Android
I tried to embed Ktor in an Android app as well. Running on an Android 5.0 Lollipop, API 21 (either real device or...
Read more >
WhatsNew 1.6 | Ktor Framework
WebSocket client closes connection due to an HTTP request timeout ... Incompatible change from io.ktor:ktor-server-core:1.6.5 to 1.6.6.
Read more >
WhatsNew 2.1 | Ktor Framework
Netty HTTP/2: response headers contain ":status" header and that leads to IllegalHeaderNameException in the ConditionalHeaders plugin.
Read more >
Response validation - Ktor
By default, Ktor doesn't validate a response depending on its status code. If required, you can use the following validation strategies:.
Read more >
WhatsNew 2.0 | Ktor Framework
Android : CIO client fail with java.security.cert.CertificateException ... WebSocket client closes connection due to an HTTP request timeout.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found