gpt4 book ai didi

android - ktor android本地http服务器抛出错误

转载 作者:行者123 更新时间:2023-12-02 12:56:10 28 4
gpt4 key购买 nike

我做了什么?

  • build.gradle 下添加了依赖项
  • implementation "io.ktor:ktor:1.3.2"
    implementation "io.ktor:ktor-server-netty:1.3.2"
    implementation "io.ktor:ktor-gson:1.3.2"
  • AndroidMenifest.xml
  • <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
  • MainActivity.kt
  • class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    embeddedServer(Netty, 9000) {
    install(ContentNegotiation) {
    gson {}
    }
    routing {
    get("/") {
    call.respond(mapOf("message" to "Hello world"))
    }
    }
    }.start(wait = true)
    }
    }
    什么地方出了错?
    运行应用程序时,出现以下错误并且 android 本地服务器未启动。
    No implementation found for int io.netty.channel.kqueue.Native.sizeofKEvent() 
    (tried Java_io_netty_channel_kqueue_Native_sizeofKEvent
    and Java_io_netty_channel_kqueue_Native_sizeofKEvent__)

    No implementation found for int io.netty.channel.epoll.Native.offsetofEpollData()
    (tried Java_io_netty_channel_epoll_Native_offsetofEpollData
    and Java_io_netty_channel_epoll_Native_offsetofEpollData__)

    最佳答案

    我是如何解决的?

  • build.gradle 下添加了依赖项
  • implementation "io.ktor:ktor:1.3.2"
    implementation "io.ktor:ktor-server-jetty:1.3.2"
    implementation "io.ktor:ktor-gson:1.3.2"
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
    ...
    minSdkVersion 26
    ...
    }
  • AndroidMenifest.xml
  • <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
  • MainActivity.kt
  • class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    embeddedServer(Jetty, 9000) {
    install(ContentNegotiation) {
    gson {}
    }
    routing {
    get("/") {
    call.respond(mapOf("message" to "Hello world"))
    }
    }
    }.start(wait = false)
    }
    }

    关于android - ktor android本地http服务器抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62500669/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com