若要为自己而活,首先必须为别人而活。——色内卡
注意这里是安卓真机设备
注意配置好HBuilderX
的gradle
配置、JDK
配置、安卓SDK
配置等,在HBuilderX
的运行配置中能找到
首先HBuilderX
新建一个uniapp-x
工程
就是在uni-app
项目默认模板下面勾选uni-app x
然后先运行到安卓手机上,我们自定义一个基座
HBuilderX
选择运行——运行到手机或模拟器——制作自定义调试基座
我这里输入包名,等待云打包完成后即可在运行到Android
真机设备时选择自定义基座运行
然后我们右键新建一个目录叫uni_modules
,右键uni_modules
新建uni_modules
插件
选择UTS
插件-API
插件新建,我这里输入的名字叫dromara-hutool
新建以后我们在uni_modules/dromara-hutool/utssdk/app-android/config.json
中引入hutool
的依赖
{
"minSdkVersion": "21",
"dependencies": [
"cn.hutool:hutool-all:5.8.26"
]
}
然后编写代码~uni_modules/dromara-hutool/utssdk/app-android/index.uts
import StrUtil from 'cn.hutool.core.util.StrUtil'
export const isNotBlank = function (str : string) : boolean {
return StrUtil.isNotBlank(str)
};
在pages/index/index.uvue
中使用
<template>
<view>
<image class="logo" src="/static/logo.png"></image>
</view>
</template>
<script>
import { isNotBlank } from '@/uni_modules/dromara-hutool'
export default {
data() {
return {
}
},
onLoad() {
console.log('isNotBlank', isNotBlank(""))
},
methods: {
}
}
</script>
<style></style>
打开页面可以看到输出:
17:34:49.167 开始差量编译...
17:34:49.198 uni_module [dromara-hutool] 三方依赖文件已存在,跳过下载
17:34:50.473 项目 simple-uts 编译成功。
17:34:50.478 正在同步手机端程序文件...
17:34:51.762 App Launch at App.uvue:5
17:34:51.762 App Show at App.uvue:8
17:34:51.763 isNotBlank [boolean] false at pages/index/index.uvue:20
17:34:52.037 应用启动到触发onLaunch耗时: 572ms
17:34:52.053 进入页面:/pages/index/index 。[{"创建dom元素个数":"4个","耗时":"22ms"},{"排版":"1次","耗时":"6ms"},{"渲染":"1次","耗时":"233ms"},{"跳转页面到onReady总耗时":"454ms"}]
成功在安卓设备执行hutool
的StrUtil.isNotBlank
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有