c***@163.com
c***@163.com
  • 发布:2024-09-16 18:12
  • 更新:2024-11-15 19:35
  • 阅读:268

求助各位大佬,uts插件开发(uts原生混编)云打包报错

分类:uni-app

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!

2024-09-16 18:12 负责人:无 分享
已邀请:
DCloud_Android_DQQ

DCloud_Android_DQQ

[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

你需要先确保,这个插件你本地可以编译通过啊

  • 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

aoaobaba

aoaobaba - 稳中有进 别急~ 慢慢来

我也没看明白,文档和示例项目关于混编插件的写法,那个NativeCode kt文件里面的对象,如何在index.uts里面直接用的?
我添加了自己的kt文件,index.uts 文件内无法识别kt 对象所在包

要回复问题请先登录注册