mdns.kt内容
package uts.sdk.modules.mlcMdns
import java.net.InetAddress
import javax.jmdns.JmDNS
import javax.jmdns.ServiceEvent
import javax.jmdns.ServiceInfo
import javax.jmdns.ServiceListener
object MdnsService {
private var jmDNS: JmDNS? = null
fun start(callback: (info: String) -> Unit) {
try {
jmDNS = JmDNS.create(InetAddress.getLocalHost())
// 注册一个服务
val serviceInfo = ServiceInfo.create("_http._tcp.local.", "My Web Server", 8080, "My web server description")
jmDNS?.registerService(serviceInfo)
// 监听服务
jmDNS?.addServiceListener("_http._tcp.local.", object : ServiceListener {
override fun serviceAdded(serviceEvent: ServiceEvent) {
callback("Service added: ${serviceEvent.info.name}")
}
override fun serviceRemoved(serviceEvent: ServiceEvent) {
callback("Service removed: ${serviceEvent.info.name}")
}
override fun serviceResolved(serviceEvent: ServiceEvent) {
callback("Service resolved: ${serviceEvent.info.name}")
}
})
} catch (e: Exception) {
e.printStackTrace()
}
}
fun stop() {
jmDNS?.unregisterAllServices()
jmDNS?.close()
}
}
index.uts文件内容
export class MdnsService implements IMdnsService{
start(callback: (res: String) => void) {
MdnsService.start(function(res: String) {
callback(res)
})
}
stop() {
MdnsService.stop()
}
}
报错内容
[HBuilder] 17:45:44.853 时间: 2024-09-16 17:44:39 类型: Android 公共测试证书 打包失败 错误日志: https://app.liuyingyong.cn/build/errorLog/4ad5a3e0-7410-11ef-b5e3-afad5e5efbf6
[HBuilder] 17:45:45.058 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
[HBuilder] 17:45:45.059 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
[HBuilder] 17:45:45.060 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
[HBuilder] 17:45:45.060 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
[HBuilder] 17:45:45.061 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
[HBuilder] 17:45:45.061 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
[HBuilder] 17:45:45.062 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
[HBuilder] 17:45:45.062 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
[HBuilder] 17:45:45.062 Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
[HBuilder] 17:45:45.063 Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
[HBuilder] 17:45:45.063 e: file://uni_modules/mlc-mdns/utssdk/app-android/src/index.kt:75:21 Unresolved reference: start
[HBuilder] 17:45:45.063 e: file://uni_modules/mlc-mdns/utssdk/app-android/src/index.kt:81:21 Unresolved reference: stop
[HBuilder] 17:45:45.064
[HBuilder] 17:45:45.064 FAILURE: Build failed with an exception.
[HBuilder] 17:45:45.064
[HBuilder] 17:45:45.065 What went wrong:
[HBuilder] 17:45:45.065 Execution failed for task ':uni_modules:mlc-mdns:compileReleaseKotlin'.
[HBuilder] 17:45:45.065 > A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
[HBuilder] 17:45:45.066 > Compilation error. See log for more details
[HBuilder] 17:45:45.066
[HBuilder] 17:45:45.066 Try:
[HBuilder] 17:45:45.067 > Run with --stacktrace option to get the stack trace.
[HBuilder] 17:45:45.067 > Run with --info or --debug option to get more log output.
[HBuilder] 17:45:45.067 > Run with --scan to get full insights.
[HBuilder] 17:45:45.068
[HBuilder] 17:45:45.068 * Get more help at https://help.gradle.org
[HBuilder] 17:45:45.068
[HBuilder] 17:45:45.068 BUILD FAILED in 33s
https://app.liuyingyong.cn/build/errorLog/4ad5a3e0-7410-11ef-b5e3-afad5e5efbf6内容
Appid: UNIB50BE18
错误解决方案
错误描述: uts插件编译失败
解决方案: 请根据编译错误修改插件相关代码后重新提交打包。或联系插件作者解决。
######################
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: unexpected element (uri:\"\", local:\"extension-level\"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
Warning: unexpected element (uri:\"\", local:\"base-extension\"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
e: file://[PackagePath]/wgtRoot/UNIB50BE18/uni_modules/mlc-mdns/utssdk/app-android/src/index.kt:75:21 Unresolved reference: start
e: file://[PackagePath]/wgtRoot/UNIB50BE18/uni_modules/mlc-mdns/utssdk/app-android/src/index.kt:81:21 Unresolved reference: stop
FAILURE: Build failed with an exception.
-
What went wrong:
Execution failed for task ':uni_modules:mlc-mdns:compileReleaseKotlin'.A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
Compilation error. See log for more details -
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights. -
Get more help at https://help.gradle.org
BUILD FAILED in 33s
Error code = -5000
Error message:
UTS plugin @ utssdk mlc-mdns compile error!
c***@163.com (作者)
你好我现在不知道uts插件中的index.uts文件内怎么调用kotlin的方法,我直接用文档上的示例代码打包的时候一直报kotlin的NativeCode找不到或者未定义的错误
2024-09-17 15:34
c***@163.com (作者)
uts原生混编那一页面的示例
2024-09-17 15:36
c***@163.com (作者)
本地运行也是报错
2024-09-17 15:37
c***@163.com (作者)
大佬,请指点一下啊,网上的资料实在太少了
2024-09-17 15:39
DCloud_Android_DQQ
回复 c***@163.com: 你使用hello uts 直接运行有问题嘛
2024-09-18 11:34
c***@163.com (作者)
回复 DCloud_Android_DQQ: 大佬可否直接说一下怎么在uts文件中调用kotlin的方法吗
2024-09-18 16:07
DCloud_Android_DQQ
回复 c***@163.com: 文档参考这个 https://doc.dcloud.net.cn/uni-app-x/plugin/uts-plugin-hybrid.html 示例参考:https://gitcode.net/dcloud/hello-uts/-/tree/dev/uni_modules/uts-syntaxcase/utssdk/app-android
2024-09-18 17:47
2***@qq.com
回复 DCloud_Android_DQQ: vue nvue也支持吗, 我直接下载这个demo然后本地运行报错
2024-09-23 12:50
2***@qq.com
回复 2***@qq.com: reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->
at eval (<anonymous>:1:7)
at 298 (pages/demo/demo.js.nvue:693:1)
at webpack_require (pages/demo/demo.js.nvue:21:30)
at eval (<anonymous>:2:583)
at 297 (pages/demo/demo.js.nvue:682:1)
at webpack_require (pages/demo/demo.js.nvue:21:30)
at eval (<anonymous>:3:104)
at 294 (pages/demo/demo.js.nvue:589:1)
at __webpack_require__ (pages/demo/demo.js.nvue:21:30)
at eval (<anonymous>:6:91)
2024-09-23 12:51
DCloud_Android_DQQ
回复 2***@qq.com: 仅支持 vue和uvue
2024-09-24 17:53