ToB企服应用市场:ToB评测及商务社交产业平台

标题: uniapp—android原生插件开发(4uniapp引用aar插件) [打印本页]

作者: 锦通    时间: 2024-11-20 17:56
标题: uniapp—android原生插件开发(4uniapp引用aar插件)
本篇文章从实战角度出发,将UniApp集成新大陆PDA设备RFID的全过程分为四部曲,涵盖环境搭建、插件开发、AAR打包、项目引入和功能调试。通过这份教程,轻松应对安卓原生插件开发与打包需求!

一、将android程序打包成aar插件包









二、uniapp引用aar原生插件包(暴露的模块名为RfidModule)









三、测试页面调用方法


        const rfidModule = uni.requireNativePlugin('RfidModule');
  1. <template>
  2.         <view class="content">
  3.                 <image class="logo" src="/static/logo.png"></image>
  4.                 <view class="text-area">
  5.                         <button @click="add">测试添加方法</button>
  6.                         <button @click="connect">初始化并连接设备</button>
  7.                         <button @click="startInventory">启动盘点</button>
  8.                         <button @click="readTagData">读取标签数据</button>
  9.                         <button @click="writeTagDataToEPC">写入标签数据</button>
  10.                         <button @click="stopInventory">停止盘点</button>
  11.                         <button @click="disconnect">断开连接</button>
  12.                 </view>
  13.         </view>
  14. </template>
  15. <script>
  16.         const rfidModule = uni.requireNativePlugin('RfidModule');
  17.         console.log(rfidModule);
  18.         export default {
  19.                 data() {
  20.                         return {
  21.                                 title: 'Hello'
  22.                         }
  23.                 },
  24.                 onLoad() {
  25.                 },
  26.                 methods: {
  27.                         // 测试添加方法
  28.                         add() {
  29.                                 rfidModule.add({
  30.                                         a: 1, b: 3
  31.                                 }, e => {
  32.                                         uni.showToast({
  33.                                                 title: "add测试方法=====" + JSON.stringify(e),
  34.                                                 icon: 'none'
  35.                                         })
  36.                                 })
  37.                                 // let rtn = rfidModule.add({
  38.                                 //         a: 1,
  39.                                 //         b: 3
  40.                                 // });
  41.                                 // console.log(rtn);
  42.                                 // uni.showToast({
  43.                                 //         title: "add测试方法=====" + JSON.stringify(rtn),
  44.                                 //         icon: 'none'
  45.                                 // })
  46.                         },
  47.                         // 初始化并连接设备
  48.                         connect() {
  49.                                 rfidModule.initialize();
  50.                                 let rtn = rfidModule.connect();
  51.                                 uni.showToast({
  52.                                         title: "初始化并连接设备=====" + JSON.stringify(rtn),
  53.                                         icon: 'none'
  54.                                 })
  55.                         },
  56.                         // 启动盘点
  57.                         startInventory() {
  58.                                 let rtn = rfidModule.startInventory()
  59.                                 uni.showToast({
  60.                                         title: "启动盘点=====" + JSON.stringify(rtn),
  61.                                         icon: 'none'
  62.                                 })
  63.                         },
  64.                         // 读取标签数据
  65.                         readTagData() {
  66.                                 let rtn = rfidModule.readTagData(2, 0, 2, "00000001");
  67.                                 uni.showToast({
  68.                                         title: "读取标签数据=====" + JSON.stringify(rtn),
  69.                                         icon: 'none'
  70.                                 })
  71.                         },
  72.                         // 写入标签数据
  73.                         writeTagDataToEPC() {
  74.                                 let rtn = rfidModule.writeTagDataToEPC("dataToWrite", "00000001");
  75.                                 uni.showToast({
  76.                                         title: "写入标签数据=====" + JSON.stringify(rtn),
  77.                                         icon: 'none'
  78.                                 })
  79.                         },
  80.                         // 停止盘点
  81.                         stopInventory() {
  82.                                 let rtn = rfidModule.stopInventory();
  83.                                 uni.showToast({
  84.                                         title: "停止盘点=====" + JSON.stringify(rtn),
  85.                                         icon: 'none'
  86.                                 })
  87.                         },
  88.                         // 断开连接
  89.                         disconnect() {
  90.                                 let rtn = rfidModule.disconnect()
  91.                                 uni.showToast({
  92.                                         title: "断开连接=====" + JSON.stringify(rtn),
  93.                                         icon: 'none'
  94.                                 })
  95.                         }
  96.                 }
  97.         }
  98. </script>
复制代码

四、制作自界说调试基座




五、uniapp真机调试自界说原生插件





此时,流程跑通了,后续根据本身的业务开发即可。

踩坑不轻易,假如对你有帮助,麻烦点个赞或收藏一下,谢谢!!!
快速通道
uniapp—android原生插件开发(1环境准备)
uniapp—android原生插件开发(2原生插件开发)
uniapp—android原生插件开发(3Android真机调试)
uniapp—android原生插件开发(4uniapp引用aar插件)

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4