l***@wenergy.com.cn
l***@wenergy.com.cn
  • 发布:2026-07-13 09:38
  • 更新:2026-07-13 09:40
  • 阅读:60

【报Bug】兼容性组件离线打包不渲染

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 22H2

HBuilderX类型: 正式

HBuilderX版本号: 5.07

手机系统: Android

手机系统版本号: Android 16

手机厂商: 魅族

手机机型: 魅族20pro

页面类型: vue

vue版本: vue3

打包方式: 离线

项目创建方式: HBuilderX

示例代码:

'''<template>
<view class="content">
webview
<uts-hello-view ref="helloView" buttontext="点击按钮内容" style="width:375px;height: 60px;background-color: aqua;"></uts-hello-view>
</view>
</template>

<script>
export default {

}  

</script>

<style>

</style>'''
'''@file:Suppress("UNCHECKED_CAST", "USELESS_CAST", "INAPPLICABLE_JVM_NAME", "UNUSED_ANONYMOUS_PARAMETER", "SENSELESS_COMPARISON", "NAME_SHADOWING", "UNNECESSARY_NOT_NULL_ASSERTION")
package uts.sdk.modules.aiwnWebview
import android.text.TextUtils
import android.view.View
import android.widget.Button
import com.taobao.weex.annotation.JSMethod
import com.taobao.weex.ui.component.WXComponentProp
import io.dcloud.feature.uniapp.UniSDKInstance
import io.dcloud.feature.uniapp.ui.action.AbsComponentData
import io.dcloud.feature.uniapp.ui.component.AbsVContainer
import io.dcloud.uniapp.
import io.dcloud.uniapp.extapi.

import io.dcloud.uts.
import io.dcloud.uts.Map
import io.dcloud.uts.Set
import io.dcloud.uts.UTSAndroid
import io.dcloud.uts.component.

import io.dcloud.uts.component.UTSComponent
import io.dcloud.uts.component.UTSMeasureMode
import io.dcloud.uts.component.UTSSize
import kotlin.properties.Delegates
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
open class UtsHelloViewComponent : UTSComponent<Button> {
constructor(instance: UniSDKInstance?, parent: AbsVContainer<>?, componentData: AbsComponentData<>?) : super(instance, parent, componentData)
open var buttontext: String = "点击触发"
override fun created() {}
override fun NVBeforeLoad() {}
override fun NVLoad(): Button {
var button = Button($androidContext!!)
button.setText("点击触发")
button.setOnClickListener(ButtonClickListener(this))
return button
}
override fun NVLoaded() {}
override fun NVLayouted() {}
override fun NVBeforeUnload() {}
override fun NVUnloaded() {}
override fun unmounted() {}
override fun NVMeasure(size: UTSSize, mode: UTSMeasureMode): UTSSize {
return size
}
@JSMethod(uiThread = false)
open fun doSomething(param: String) {
console.log(param)
}
open fun privateMethod() {}
override fun $init() {
this.$watch<String>("buttontext", fun(newValue, oldValue){
if (!TextUtils.isEmpty(newValue) && newValue != oldValue) {
this.$el?.setText(newValue)
}
}
)
}
@WXComponentProp(name = "buttontext")
open fun componentSetButtontext(value: String) {
this.buttontext = value
this.$componentWatchDispatch("buttontext", value)
}
}
open class ButtonClickListener : View.OnClickListener {
private var comp: UTSComponent<Button>
constructor(comp: UTSComponent<Button>) : super() {
this.comp = comp
}
override fun onClick(v: View?) {
console.log("按钮被点击")
this.comp.$emit("buttonclick")
}
}
'''
'''
{
"nativePlugins": [
{
"plugins": [
{
"type": "component",
"name": "uts-hello-view",
"class": "uts.sdk.modules.aiwnWebview.UtsHelloViewComponent"
}
]
}
]
}
'''

操作步骤:

根据官网离线打包配置。运行后组件没有渲染。

预期结果:

出现uts-hello-view组件

实际结果:

不渲染uts-hello-view组件

bug描述:

兼容性组件离线打包配置不显示?
根据官网配置的uts-hello-view组件,在nvue页面使用,离线打包后根本不显示。
setting.gradle.以及ibuild.gradle都已经添加peizhile.

2026-07-13 09:38 负责人:无 分享
已邀请:
Ask小助手

Ask小助手 - Ask社区AI助手

欢迎到专业群( uni-app x技术交流群 ) 咨询,群中有相关专业的管理员和群友。

感谢您的反馈。针对您提交的 Bug 反馈,我们进行了评审与分析,以下是具体的评审意见及排查建议:

1. Bug 反馈内容完整性评审

  • BUG 描述:描述较为简略。仅说明了“根据官网配置”以及 setting.gradlebuild.gradle 已配置,但未具体说明配置的内容。离线打包涉及诸多细节配置,建议补充具体的配置代码。
  • 代码示例:提供的代码示例不完整且存在格式问题。uts 原生代码与 json 配置直接混排,未明确区分文件。此外,根据官方文档,UTS 兼容模式组件的源码应编写在 index.vue 文件中,而您提供的是编译后的 Kotlin 代码,这不利于官方人员直接运行和排查。
  • 复现步骤:复现步骤过于简单(“根据官网离线打包配置”),未提供可复现的完整工程或更详细的操作指引,官方人员难以直接复现。
  • 预期与实际结果:预期结果合理,实际结果描述清晰。
  • 分类信息:分类信息完整,包含了 HBuilderX 版本、手机系统及机型等关键信息。

2. Bug 是否成立分析

根据知识库信息,该 Bug 暂无法直接判定为框架缺陷,更可能是离线打包配置或组件使用方式的问题。主要排查方向如下:

配置文件缺失或错误
根据社区经验,离线打包时 UTS 插件的配置容易遗漏。请重点检查以下内容:

  • dcloud_uniplugins.json 配置:您提供的 nativePlugins JSON 结构似乎不完整。标准配置应包含 plugins 数组,并明确指定 typenameclass。请确认该文件是否已正确放置在 src/main/assets/apps/您的appid/www/ 目录下或按官方要求配置。
  • build.gradle 依赖:确认 uniappx 模块或 app 模块下是否正确配置了 UTS 插件的依赖。参考 Uniappx 离线打包配置uniappx 离线打包,确保 io.dcloud.uts.kotlin 插件已正确引入。
  • buildConfigField 配置:参考 优先知识库,某些组件或 API 需要在 build.gradle 中配置 buildConfigField 'String', 'UTSEasyCom', ... 以注册组件,请检查是否遗漏。

组件使用方式差异
根据 UTS 组件兼容模式文档,UTS 组件默认全局注册,但在 uvue 页面和 nvue 页面中的使用方式存在差异:

  • nvue 页面中,可以通过 this.$refs["helloView"].doSomething(...) 直接调用方法。
  • uvue 页面中,需要引入对应的 Element 类型并进行类型转换,例如:(this.$refs["helloView"] as UtsHelloViewElement).doSomething(...)

组件源码结构
根据 UTS 组件结构解析,UTS 兼容模式组件应使用 export default {} 的选项式 API 编写在 index.vue 中。请检查您的组件源码是否符合此规范,特别是 NVLoad() 方法是否正确返回了原生 View 对象。

3. 后续建议

由于目前提供的信息不足以直接定位问题,建议您:

  1. 对照 UTS 组件开发文档离线打包文档 仔细检查配置。
  2. 尝试下载官方的 Hello uni-app x 示例工程,在本地运行离线打包,对比配置差异。
  3. 如果问题仍然存在,请在 DCloud Issue 系统 提交问题,并提供一个可直接运行的、最小化的复现工程(包含完整的 Android 离线打包项目及 UTS 插件源码),以便我们快速定位。
内容为 AI 生成,仅供参考

要回复问题请先登录注册