xzh
xzh
  • 发布:2022-09-03 12:48
  • 更新:2022-09-08 10:55
  • 阅读:869

【报Bug】uts编译生成kt文件丢失导入类

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

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

HBuilderX类型: Alpha

HBuilderX版本号: 3.6.0

手机系统: Android

手机系统版本号: Android 9.0

手机厂商: 小米

手机机型: 所有

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:

说明已经说明了,下面也有附件

预期结果:

导入的类不丢失

实际结果:

导入的类丢失

bug描述:

uts编译 kt 的时候,因为导入android.view.View类,但没有实例化,所以编译成 kt 文件的时候没有导入android.view.View,然后造成override onClick(view: View): void,找不到View报异常,这是控制台信息error: unresolved reference: View override fun onClick(view: View): Unit {

uts代码

// 引用uts环境库  
import { getAppContext, getUniActivity } from "io.dcloud.uts.android";  
// 引用android api  
import View from "android.view.View"  
import OnClickListener from "android.view.View.OnClickListener"  
import OnTouchListener from "android.view.View.OnTouchListener"  
import MotionEvent from "android.view.MotionEvent"  
import LayoutInflater from "android.view.LayoutInflater"  
import PixelFormat from "android.graphics.PixelFormat"  
import WindowManager from "android.view.WindowManager"  
import LayoutParams from "android.view.WindowManager.LayoutParams"  
import Runnable from 'java.lang.Runnable';  
import Toast from "android.widget.Toast";  
import TextView from "android.widget.TextView";  
import Rect from "android.graphics.Rect";  
import Color from "android.graphics.Color";  
import FrameLayout from "android.widget.FrameLayout";  
import Gravity from "android.view.Gravity";  
import ViewGroup from "android.view.ViewGroup";  

class AddUIRunnable extends Runnable {  
    override run():void {  

        let textView = new TextView(getUniActivity())  
        textView.setText("HELLO WORLD");  
        textView.textSize = 30.0.toFloat();  
        textView.setBackgroundColor(Color.RED)  
        textView.setTag("helloText")  
        textView.setGravity(Gravity.CENTER)  

        textView.setOnClickListener(new ViewClickListener())  

        let decorView = getUniActivity()!.window.decorView;  

        let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)  
        let layoutParam = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);  
        layoutParam.topMargin = 200;  

        frameContent.addView(textView,layoutParam)  

    }  
};  

class ViewClickListener extends OnClickListener {  
    override onClick(view: View): void {  
        Toast.makeText(getUniActivity()!, "点击", Toast.LENGTH_SHORT).show()  
    }  
}  

export function addViewToDecorView() {  
    let uiRunable = new AddUIRunnable();  
    getUniActivity()!.runOnUiThread(uiRunable)  

}

kt

package uts.sdk.modules.utsTest;  
import kotlinx.coroutines.async;  
import kotlinx.coroutines.CoroutineScope;  
import kotlinx.coroutines.Deferred;  
import kotlinx.coroutines.Dispatchers;  
import io.dcloud.uts.*;  
import io.dcloud.uts.android.getUniActivity;  
import android.view.View.OnClickListener;  
import java.lang.Runnable;  
import android.widget.Toast;  
import android.widget.TextView;  
import android.graphics.Color;  
import android.widget.FrameLayout;  
import android.view.Gravity;  
import android.view.ViewGroup;  
open class AddUIRunnable : Runnable {  
    override fun run(): Unit {  
        var textView = TextView(getUniActivity());  
        textView.setText("HELLO WORLD");  
        textView.textSize = 30.0.toFloat();  
        textView.setBackgroundColor(Color.RED);  
        textView.setTag("helloText");  
        textView.setGravity(Gravity.CENTER);  
        textView.setOnClickListener(ViewClickListener());  
        var decorView = getUniActivity()!!.window.decorView;  
        var frameContent = decorView.findViewById<FrameLayout>(android.R.id.content);  
        var layoutParam = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);  
        layoutParam.topMargin = 200;  
        frameContent.addView(textView, layoutParam);  
    }  
}  
open class ViewClickListener : OnClickListener {  
    override fun onClick(view: View): Unit {  
        Toast.makeText(getUniActivity()!!, "点击", Toast.LENGTH_SHORT).show();  
    }  
}  
fun addViewToDecorView() {  
    var uiRunable = AddUIRunnable();  
    getUniActivity()!!.runOnUiThread(uiRunable);  
}  

下面我也上传了附件

2022-09-03 12:48 负责人:无 分享
已邀请:
DCloud_UNI_FXY

DCloud_UNI_FXY

已确定,可以临时使用 import "android.view.View" 绕过

DCloud_UNI_FXY

DCloud_UNI_FXY

HBuilderX Alpha 3.6.1 已修复

该问题目前已经被锁定, 无法添加新回复