了解更多开源请访问:开源基础软件社区https://ost.51cto。com安装说明(Open-Harmony)蓝牙专用应用在开源鸿蒙系统中的路径为:foundation/communication/bluetooth/test/example/BluetoothTest目录结构。├──示例│├──BluetoothTest││├──build-profile.json5││├──hvigorfile.js││├──package.json││├──package-lock.json││├──BUILD.gn││├──entry/src/main...─controller│││││├──model│││││├──pages│││││└──res││││││└──图像│││├──MainAbility2││││└──实用程序││└──资源│││└──基础│││├──元素││││媒体│└──signature├──fuzztest├──moduletest└──unittest开源鸿蒙下的编译是应用了原系统编写的hap程序编译模板,所以保留了模板中的一些结构,如:MainAbility2和配置。json中的js语句;它对程序本身的编译没有影响。在bundle.json中添加编译命令。路径为:foundation/communication/bluetooth/bundle.json命令为:"test":[..."//foundation/communication/bluetooth/test/example/example_btTest:BluetoothTest"]添加BUILD.gnfoundation/communication/bluetooth/测试/示例/BluetoothTest/BUILD.gnimport("//test/xts/tools/build/suite.gni")ohos_hap("BluetoothTest"){hap_profile="entry/src/main/config.json"hap_name="BluetoothTest"subsystem_name=XTS_SUITENAMEfinal_hap_path="${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/testcases/${hap_name}.hap"deps=[":bluetooth_resources",":bluetooth_ts_assets",]certificate_profile="signature/auto_ohos_default_com.ohos.bttest.p7b"}ohos_js_assets("bluetooth_ts_assets"){source_dir="entry/src/main/ets"hap_profile="entry/src/main/config.json"ets2abc=true}ohos_resources("bluetooth_resources"){sources=["entry/src/main/resources"]hap_profile="entry/src/main/config.json"}创建签名文件夹,添加签名文件。路径为:foundation/communication/bluetooth/test/example/example_btTest/signature签名文件为:Dev-Eco自动签名生成的文件:auto_ohos_default_com.ohos.bttest.p7bconfig.json{"app":{"vendor":"samples","bundleName":"ohos.samples.bttest","version":{"code":1000000,"name":"1.0.0"},"apiVersion":{"compatible":8,"target":8}},"deviceConfig":{},"module":{"mainAbility":".MainAbility","deviceType":["default","phone"],"reqPermissions":[{"reason":"","name":"ohos.permission.DISCOVER_BLUETOOTH"},{"reason":"","name":"ohos.permission.USE_BLUETOOTH"},{"name":"ohos.permission.LOCATION"}],"abilities":[{"skills":[{"entities":["entity.system.home"],"actions":["action.system.home"]}],"方向”:“未指定”,“可见”:真,“srcPath”:“MainAbility”,“名称”:“.MainAbility”,“srcLanguage”:“ets”,“图标”:“$media:icon”,“description":"$string:MainAbility_desc","formsEnabled":false,"label":"$string:MainAbility_label","type":"page","launchType":"singleton"},{"orientation":"未指定”,“可见”:真实,“srcPath”:“MainAbility2”,“名称”:“.MainAbility2”,“srcLanguage”:“ets”,“图标”:“$media:icon”,“描述”:“$string:MainAbility2_desc","formsEnabled":false,"label":"$string:MainAbility2_label","type":"page","launchType":"singleton"}],"distro":{"moduleType":"entry","installationFree":false,"deliveryWithInstall":true,"moduleName":"entry"},"package":"ohos.samples.bttest","srcPath":"","name":".entry","js":[{"mode":{"syntax":"ets","type":"pageAbility"},"pages":["pages/homePage","pages/manualApiTestPage",...],"name":".MainAbility","window":{"designWidth":720,"autoDesignWidth":false}},{"mode":{"syntax":"ets","type":"pageAbility"},"pages":["pages/index"],"name":".MainAbility2","window":{"designWidth":720,"autoDesignWidth":false}}]}}编译命令#完整编译。/build.sh--product-name{product_name}#单独编译HAP。/build.sh--product-name{product_name}--build-targetBluetoothTest生成的文件使用findout-name"BluetoothTest.hap*”找到生成的文件,或者直接查看config.json中写的生成路径,将生成的文件复制到本地电脑,连接板子,使用命令hdc_std.exeinstallBluetoothTest进行安装。使用命令hdc_stduninstall{安装包名称}卸载。安装包名称在entry\src\main\config.json,如:"bundleName":"com.ohos.bttest"补充鸿蒙系统下编译,还是存在高低版本不兼容的问题版本。即mater版本下编译的hap无法在beta2版本运行;反之亦然。可能出现的编译错误有些属性必须初始化为默认值。例如:@State属性'bgColor''settingArrow''settingSummary'必须指定默认值。注意引用路径中文件名的大小写。有些属性名会与重复的关键字或类名冲突。例如:类型“EntryComponent”中的属性“height”/“onClick”/“enabled”不能分配给基本类型“CustomComponent”中的相同属性。只需将其更改为例如“isOnClick”/“isEnabled”。一些资源,如:@StatesettingSummary:Resource必须是资源,不能添加|string或分配字符串。类型“资源”不可分配给类型“字符串”。反之亦然。类型“字符串”不可分配给类型“资源”。了解更多开源知识,请访问:开源基础软件社区https://ost.51cto.com。
