跟著小白一起學鴻蒙—如何編譯Hap程序(十七)
作者:王石 胡瑞濤
本篇我們來學習如何在鴻蒙環境下編譯Hap程序。
安裝使用說明(Open-Harmony)
在開源鴻蒙系統下
- 藍牙專項應用程序路徑為:foundation/communication/bluetooth/test/example/BluetoothTest
- 目錄結構
- 在開源鴻蒙下的編譯,是套用了原本系統中編寫好的hap程序編譯模板,因此保留了一些模板中的結構,如:MainAbility2 和config.json中的js語句;對程序本身的編譯沒有影響。
- 在bundle.json中添加編譯命令。
- 添加BUILD.gn
- 創建signature文件夾,添加簽名文件。
- config.json
- 編譯命令
- 生成文件
- 使用 find out -name “BluetoothTest.hap*” 查找生成文件,或者直接查看config.json所寫的生成路徑。
- 將生成文件拷到本地電腦上,連接板子,使用命令hdc_std.exe install BluetoothTest進行安裝。
- 使用命令hdc_std uninstall {安裝包名} 進行卸載。
- 安裝包名在entry\src\main\config.json 如:"bundleName": "com.ohos.bttest"
- 補充
在鴻蒙系統下編譯,仍存在高版本對低版本的編譯不兼容性問題。即在mater版本下編譯的hap無法在beta2版本運行;反之則可以。 - 可能出現的編譯報錯
- 一些屬性必須初始化一個默認值。如:The @State property ‘bgColor’ ‘settingArrow’ ‘settingSummary’ must be specified a default value。
- 注意引用路徑中的文件名大小寫問題。
- 一些屬性名與關鍵詞或類名重復會起沖突。如: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’。
責任編輯:jianghua
來源:
51CTO開源基礎軟件社區