自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

跟著小白一起學(xué)鴻蒙—如何編譯Hap程序(十七)

系統(tǒng) OpenHarmony
本篇我們來學(xué)習(xí)如何在鴻蒙環(huán)境下編譯Hap程序。

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

安裝使用說明(Open-Harmony)

在開源鴻蒙系統(tǒng)下

  • 藍(lán)牙專項應(yīng)用程序路徑為:foundation/communication/bluetooth/test/example/BluetoothTest
  • 目錄結(jié)構(gòu)
.
├── example
├── BluetoothTest
├── build-profile.json5
├── hvigorfile.js
├── package.json
├── package-lock.json
├── BUILD.gn
├── entry/src/main
├── config.json
├── ets
├── Component
├── MainAbility
├── app.ets
├── controller
├── model
├── pages
└── res
└── image
├── MainAbility2
└── Utils
└── resources
└── base
├── element
└── media
└── signature
├── fuzztest
├── moduletest
└── unittest
  • 在開源鴻蒙下的編譯,是套用了原本系統(tǒng)中編寫好的hap程序編譯模板,因此保留了一些模板中的結(jié)構(gòu),如:MainAbility2 和config.json中的js語句;對程序本身的編譯沒有影響。
  • 在bundle.json中添加編譯命令。
路徑為:foundation/communication/bluetooth/bundle.json
命令為:
"test": [
...
"http://foundation/communication/bluetooth/test/example/example_btTest:BluetoothTest"
]
  • 添加BUILD.gn
foundation/communication/bluetooth/test/example/BluetoothTest/BUILD.gn
import("http://test/xts/tools/build/suite.gni")
ohos_hap("BluetoothTest") {
hap_profile = "entry/src/main/config.json"
hap_name = "BluetoothTest"
subsystem_name = XTS_SUITENAME
final_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"
}
  • 創(chuàng)建signature文件夾,添加簽名文件。

路徑為:foundation/communication/bluetooth/test/example/example_btTest/signature
簽名文件為:Dev-Eco自動簽名生成的文件:auto_ohos_default_com.ohos.bttest.p7b

  • config.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"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"formsEnabled": false,
"label": "$string:MainAbility_label",
"type": "page",
"launchType": "singleton"
},
{
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility2",
"name": ".MainAbility2",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$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}

# 單獨(dú)編譯HAP
./build.sh --product-name {product_name} --build-target BluetoothTest

  • 生成文件
  • 使用 find out -name “BluetoothTest.hap*” 查找生成文件,或者直接查看config.json所寫的生成路徑。
  • 將生成文件拷到本地電腦上,連接板子,使用命令hdc_std.exe install BluetoothTest進(jìn)行安裝。
  • 使用命令hdc_std uninstall {安裝包名} 進(jìn)行卸載。
  • 安裝包名在entry\src\main\config.json 如:"bundleName": "com.ohos.bttest"
  • 補(bǔ)充
    在鴻蒙系統(tǒng)下編譯,仍存在高版本對低版本的編譯不兼容性問題。即在mater版本下編譯的hap無法在beta2版本運(yùn)行;反之則可以。
  • 可能出現(xiàn)的編譯報錯
  • 一些屬性必須初始化一個默認(rèn)值。如:The @State property ‘bgColor’ ‘settingArrow’ ‘settingSummary’ must be specified a default value。
  • 注意引用路徑中的文件名大小寫問題。
  • 一些屬性名與關(guān)鍵詞或類名重復(fù)會起沖突。如:Property ‘height’/“onClick”/“enabled” in type ‘EntryComponent’ is not assignable to the same property in base type 'CustomComponent。將其改成例如"isOnClick"/"isEnabled"即可。
  • 一些資源,如:@State settingSummary: Resource 必須是resource 不能加 |string 或者賦值為string。Type ‘Resource’ is not assignable to type ‘string’. 反之同理。Type ‘string’ is not assignable to type ‘Resource’。

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??。

責(zé)任編輯:jianghua 來源: 51CTO開源基礎(chǔ)軟件社區(qū)
相關(guān)推薦

2022-12-06 15:39:16

鴻蒙主干代碼

2022-11-29 16:35:02

Tetris鴻蒙

2022-12-02 14:20:09

Tetris鴻蒙

2022-12-09 15:34:38

2022-11-14 17:01:34

游戲開發(fā)畫布功能

2023-03-30 09:32:27

2023-02-27 16:30:32

鴻蒙開源協(xié)議分析

2022-08-19 19:02:20

開源鴻蒙操作系統(tǒng)

2023-03-30 09:19:54

SELinux安全子系統(tǒng)

2023-04-04 09:24:11

鴻蒙HiDumper

2022-10-10 14:47:04

藍(lán)牙應(yīng)用鴻蒙

2022-09-30 14:08:26

Hap應(yīng)用鴻蒙

2022-11-25 16:48:54

鴻蒙Stage HAP

2023-01-03 15:09:10

鴻蒙常用工具

2022-08-29 17:25:19

鴻蒙應(yīng)用開發(fā)

2022-10-20 16:40:16

JS應(yīng)用控制LED鴻蒙

2022-10-09 15:05:50

NAPI框架鴻蒙

2023-03-15 16:19:03

BinderIPC工具

2022-11-03 15:47:04

HTTP通信協(xié)議

2022-11-08 15:43:45

開源鴻蒙藍(lán)牙協(xié)議棧
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號