跟著小白一起學(xué)鴻蒙—如何編譯Hap程序(十七)
作者:王石 胡瑞濤
本篇我們來學(xué)習(xí)如何在鴻蒙環(huán)境下編譯Hap程序。
??想了解更多關(guān)于開源的內(nèi)容,請訪問:??
安裝使用說明(Open-Harmony)
在開源鴻蒙系統(tǒng)下
- 藍(lán)牙專項應(yīng)用程序路徑為:foundation/communication/bluetooth/test/example/BluetoothTest
- 目錄結(jié)構(gòu)
- 在開源鴻蒙下的編譯,是套用了原本系統(tǒng)中編寫好的hap程序編譯模板,因此保留了一些模板中的結(jié)構(gòu),如:MainAbility2 和config.json中的js語句;對程序本身的編譯沒有影響。
- 在bundle.json中添加編譯命令。
- 添加BUILD.gn
- 創(chuàng)建signature文件夾,添加簽名文件。
- config.json
- 編譯命令
- 生成文件
- 使用 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’。
責(zé)任編輯:jianghua
來源:
51CTO開源基礎(chǔ)軟件社區(qū)