I'm trying to create local server on android app that can handle some complex JS Codes, I end up testing Ktor For creating the local server
implementation("io.ktor:ktor-server-core:2.3.9")
implementation("io.ktor:ktor-server-netty:2.3.9")
implementation("io.ktor:ktor-features:2.3.9")
implementation("io.ktor:ktor-server-compression:2.3.9")
implementation("io.ktor:ktor-server-call-logging:2.3.9")
implementation("io.ktor:ktor-server-status-pages:2.3.9")
and this is my server class
class KtorAppServer(private val context: Context, private val callback: ServerCallback, private val root: File?) {
interface ServerCallback {
fun onStarted()
fun onStopped()
fun onError(message: String)
}
private lateinit var server: NettyApplicationEngine
init {
startServer()
}
private fun startServer() {
server = embeddedServer(Netty, port = 8080) {
install(CallLogging) {
level = org.slf4j.event.Level.INFO
filter { call -> call.request.path().startsWith("/") }
}
install(Compression) {
gzip()
}
install(StatusPages) {
status(HttpStatusCode.NotFound) { call, status ->
call.respondText(text = "404: Page Not Found", status = status)
}
}
routing {
staticFiles("/",root!!,"test.html")
}
}.apply {
try {
start(wait = false)
Log.d("AppServer", "Server started on port 8080")
callback.onStarted()
} catch (e: Exception) {
Log.e("AppServer", "Error starting server: ${e.message}")
callback.onError(e.message ?: "Unknown error")
}
}
}
}
but I'm Unable to build the app having this error "Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugCompileClasspath'." is it even possible to run Ktor server on android app ? the documentation is all about JVM