1# Development Guidelines<a name="EN-US_TOPIC_0000001062229264"></a> 2 3- [When to Use](#section93012287133) 4- [Available APIs](#section11821047161319) 5- [How to Develop](#section10514141679) 6 - [Creating a Service Ability](#section19921154214315) 7 - [Development Guidelines on Bundle Management](#section1724016743217) 8 - [Packing a HAP File](#section171771212328) 9 10 11## When to Use<a name="section93012287133"></a> 12 13- Develop Page abilities for applications that have a UI for human-machine interaction, such as news applications, video players, navigation applications, and payment applications. Most applications we use in our daily lives are such type of applications. 14 15- Develop Service abilities for applications so that they can run particular services in the background, such as music playing, computing, and navigation services. 16 17- Pack both Page and Service abilities into HarmonyOS Ability Packages \(HAPs\). All applications must be packed into HAP files before being published to the application market. Once published, users can then download the applications from the application market. 18 19## Available APIs<a name="section11821047161319"></a> 20 21**Table 1** APIs of the ability management framework 22 23<a name="table36761640135514"></a> 24<table><thead align="left"><tr id="row570215713380"><th class="cellrowborder" valign="top" width="53.849999999999994%" id="mcps1.2.3.1.1"><p id="p1703155733819"><a name="p1703155733819"></a><a name="p1703155733819"></a>Function</p> 25</th> 26<th class="cellrowborder" valign="top" width="46.150000000000006%" id="mcps1.2.3.1.2"><p id="p37035579380"><a name="p37035579380"></a><a name="p37035579380"></a>Description</p> 27</th> 28</tr> 29</thead> 30<tbody><tr id="row39211240205510"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p49215401550"><a name="p49215401550"></a><a name="p49215401550"></a>Want *WantParseUri(const char *uri)</p> 31</td> 32<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p592164014553"><a name="p592164014553"></a><a name="p592164014553"></a>Converts a specified character string into a <strong id="b123303298245"><a name="b123303298245"></a><a name="b123303298245"></a>Want</strong> object.</p> 33</td> 34</tr> 35<tr id="row192154055512"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p139212040175520"><a name="p139212040175520"></a><a name="p139212040175520"></a>const char *WantToUri(Want want)</p> 36</td> 37<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p9921640135519"><a name="p9921640135519"></a><a name="p9921640135519"></a>Converts a specified <strong id="b26361419162420"><a name="b26361419162420"></a><a name="b26361419162420"></a>Want</strong> object into a character string.</p> 38</td> 39</tr> 40<tr id="row16921440135520"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1892124075519"><a name="p1892124075519"></a><a name="p1892124075519"></a>void SetWantElement(Want *want, ElementName element);</p> 41</td> 42<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p129214403555"><a name="p129214403555"></a><a name="p129214403555"></a>Sets the <strong id="b6704163515267"><a name="b6704163515267"></a><a name="b6704163515267"></a>element</strong> variable for a specified <strong id="b1759143810269"><a name="b1759143810269"></a><a name="b1759143810269"></a>Want</strong> object.</p> 43</td> 44</tr> 45<tr id="row3921114018552"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p79210404555"><a name="p79210404555"></a><a name="p79210404555"></a>void SetWantData(Want *want, const void *data, uint16_t dataLength)</p> 46</td> 47<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p09218402559"><a name="p09218402559"></a><a name="p09218402559"></a>Sets data to carry in a specified <strong id="b1317045311262"><a name="b1317045311262"></a><a name="b1317045311262"></a>Want</strong> object for starting a particular ability.</p> 48</td> 49</tr> 50<tr id="row892124013556"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p4921040155510"><a name="p4921040155510"></a><a name="p4921040155510"></a>bool SetWantSvcIdentity(Want *want, SvcIdentity sid)</p> 51</td> 52<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p992204013553"><a name="p992204013553"></a><a name="p992204013553"></a>Sets the <strong id="b171231625124319"><a name="b171231625124319"></a><a name="b171231625124319"></a>sid</strong> member variable for a specified <strong id="b11565173054314"><a name="b11565173054314"></a><a name="b11565173054314"></a>Want</strong> object.</p> 53</td> 54</tr> 55<tr id="row99221840135520"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p139221840155519"><a name="p139221840155519"></a><a name="p139221840155519"></a>void ClearWant(Want *want)</p> 56</td> 57<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p79221440185511"><a name="p79221440185511"></a><a name="p79221440185511"></a>Clears the memory of a specified <strong id="b233731018449"><a name="b233731018449"></a><a name="b233731018449"></a>Want</strong> object.</p> 58</td> 59</tr> 60<tr id="row69221640125519"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1792244017555"><a name="p1792244017555"></a><a name="p1792244017555"></a>void SetMainRoute(const std::string &entry)</p> 61</td> 62<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p7922174016558"><a name="p7922174016558"></a><a name="p7922174016558"></a>Sets the main route for the ability.</p> 63</td> 64</tr> 65<tr id="row189221840165516"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p3922340125511"><a name="p3922340125511"></a><a name="p3922340125511"></a>void SetUIContent(RootView *rootView)</p> 66</td> 67<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p9922240175511"><a name="p9922240175511"></a><a name="p9922240175511"></a>Sets the UI layout for the ability.</p> 68</td> 69</tr> 70<tr id="row159226407552"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1292213402552"><a name="p1292213402552"></a><a name="p1292213402552"></a>void OnStart(const Want& intent)</p> 71</td> 72<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p14922440195515"><a name="p14922440195515"></a><a name="p14922440195515"></a>Called when the ability is started. This callback is invoked to handle transitions between ability lifecycle states.</p> 73</td> 74</tr> 75<tr id="row1392217402551"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1292284065516"><a name="p1292284065516"></a><a name="p1292284065516"></a>void OnStop()</p> 76</td> 77<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p149223403554"><a name="p149223403554"></a><a name="p149223403554"></a>Called when the ability is being destroyed. This callback is invoked to handle transitions between ability lifecycle states.</p> 78</td> 79</tr> 80<tr id="row169221407555"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p992218400556"><a name="p992218400556"></a><a name="p992218400556"></a>void OnActive(const Want& intent)</p> 81</td> 82<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p1923440135515"><a name="p1923440135515"></a><a name="p1923440135515"></a>Called when the ability is visible to users. This callback is invoked to handle transitions between ability lifecycle states.</p> 83</td> 84</tr> 85<tr id="row9923640205516"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p19231340185511"><a name="p19231340185511"></a><a name="p19231340185511"></a>void OnInactive()</p> 86</td> 87<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p992311408556"><a name="p992311408556"></a><a name="p992311408556"></a>Called when the ability is invisible to users. This callback is invoked to handle transitions between ability lifecycle states.</p> 88</td> 89</tr> 90<tr id="row4923154015557"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p99233404556"><a name="p99233404556"></a><a name="p99233404556"></a>void OnBackground()</p> 91</td> 92<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p79238400554"><a name="p79238400554"></a><a name="p79238400554"></a>Called when the ability is moved to the background. This callback is invoked to handle transitions between ability lifecycle states.</p> 93</td> 94</tr> 95<tr id="row14923144045513"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p692354019558"><a name="p692354019558"></a><a name="p692354019558"></a>const SvcIdentity *OnConnect(const Want &want)</p> 96</td> 97<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p17923154085512"><a name="p17923154085512"></a><a name="p17923154085512"></a>Called when the Service ability is connected for the first time.</p> 98</td> 99</tr> 100<tr id="row592313405552"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1692312404551"><a name="p1692312404551"></a><a name="p1692312404551"></a>void OnDisconnect(const Want &want);</p> 101</td> 102<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p892394017551"><a name="p892394017551"></a><a name="p892394017551"></a>Called when all abilities connected to the Service ability are disconnected.</p> 103</td> 104</tr> 105<tr id="row3923194075515"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p5923240175516"><a name="p5923240175516"></a><a name="p5923240175516"></a>void MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply);</p> 106</td> 107<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p2923184055518"><a name="p2923184055518"></a><a name="p2923184055518"></a>Handles a message sent by the client to the Service ability.</p> 108</td> 109</tr> 110<tr id="row15923540155517"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p99231940105514"><a name="p99231940105514"></a><a name="p99231940105514"></a>void Dump(const std::string &extra)</p> 111</td> 112<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p18924174016554"><a name="p18924174016554"></a><a name="p18924174016554"></a>Prints ability information to the console.</p> 113</td> 114</tr> 115<tr id="row1792414055517"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1592454025513"><a name="p1592454025513"></a><a name="p1592454025513"></a>void Present(AbilitySlice *abilitySlice, const Want &want)</p> 116</td> 117<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p11924104045517"><a name="p11924104045517"></a><a name="p11924104045517"></a>Presents another ability slice.</p> 118</td> 119</tr> 120<tr id="row15924114012556"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p13924154017551"><a name="p13924154017551"></a><a name="p13924154017551"></a>void Terminate()</p> 121</td> 122<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p11924104012557"><a name="p11924104012557"></a><a name="p11924104012557"></a>Destroys the ability slice.</p> 123</td> 124</tr> 125<tr id="row2092484010558"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p4924540155515"><a name="p4924540155515"></a><a name="p4924540155515"></a>void SetUIContent(RootView *rootView)</p> 126</td> 127<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p79241640185514"><a name="p79241640185514"></a><a name="p79241640185514"></a>Sets the UI layout for the host ability of the ability slice.</p> 128</td> 129</tr> 130<tr id="row16924640195518"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p169245407559"><a name="p169245407559"></a><a name="p169245407559"></a>void OnStart(const Want& want)</p> 131</td> 132<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p492494095517"><a name="p492494095517"></a><a name="p492494095517"></a>Called when the ability slice is started. This callback is invoked to handle transitions between ability slice lifecycle states.</p> 133</td> 134</tr> 135<tr id="row15924154065513"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p159242407559"><a name="p159242407559"></a><a name="p159242407559"></a>void OnStop()</p> 136</td> 137<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p13924114017556"><a name="p13924114017556"></a><a name="p13924114017556"></a>Called when the ability slice is being destroyed. This callback is invoked to handle transitions between ability slice lifecycle states.</p> 138</td> 139</tr> 140<tr id="row13924154065517"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p292494005513"><a name="p292494005513"></a><a name="p292494005513"></a>void OnActive(const Want& want)</p> 141</td> 142<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p89256408553"><a name="p89256408553"></a><a name="p89256408553"></a>Called when the ability slice is visible to users. This callback is invoked to handle transitions between ability slice lifecycle states.</p> 143</td> 144</tr> 145<tr id="row1925540125515"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p13925114015514"><a name="p13925114015514"></a><a name="p13925114015514"></a>void OnInactive()</p> 146</td> 147<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p892534025515"><a name="p892534025515"></a><a name="p892534025515"></a>Called when the ability slice is invisible to users. This callback is invoked to handle transitions between ability slice lifecycle states.</p> 148</td> 149</tr> 150<tr id="row692519401558"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1792515408558"><a name="p1792515408558"></a><a name="p1792515408558"></a>void OnBackground()</p> 151</td> 152<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p292554013551"><a name="p292554013551"></a><a name="p292554013551"></a>Called when the ability slice is moved to the background. This callback is invoked to handle transitions between ability slice lifecycle states.</p> 153</td> 154</tr> 155<tr id="row129251040115515"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p0925174011553"><a name="p0925174011553"></a><a name="p0925174011553"></a>int StartAbility(const Want &want)</p> 156</td> 157<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p129251408557"><a name="p129251408557"></a><a name="p129251408557"></a>Starts an ability based on the specified <strong id="b3667652155017"><a name="b3667652155017"></a><a name="b3667652155017"></a>Want</strong> information.</p> 158</td> 159</tr> 160<tr id="row3925940195519"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p19251440135512"><a name="p19251440135512"></a><a name="p19251440135512"></a>int StopAbility(const Want &want)</p> 161</td> 162<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p19925174035510"><a name="p19925174035510"></a><a name="p19925174035510"></a>Stops a Service ability based on the specified <strong id="b1176241795114"><a name="b1176241795114"></a><a name="b1176241795114"></a>Want</strong> information.</p> 163</td> 164</tr> 165<tr id="row14925164055520"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p14925114015553"><a name="p14925114015553"></a><a name="p14925114015553"></a>int TerminateAbility()</p> 166</td> 167<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p39254405557"><a name="p39254405557"></a><a name="p39254405557"></a>Destroys the ability.</p> 168</td> 169</tr> 170<tr id="row19925940115515"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p892584015559"><a name="p892584015559"></a><a name="p892584015559"></a>int ConnectAbility(const Want &want, const IAbilityConnection &conn, void *data);</p> 171</td> 172<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p4926640165513"><a name="p4926640165513"></a><a name="p4926640165513"></a>Connects to a <strong id="b10891169125217"><a name="b10891169125217"></a><a name="b10891169125217"></a>Service</strong> ability based on the specified <strong id="b184091115165216"><a name="b184091115165216"></a><a name="b184091115165216"></a>Want</strong> information.</p> 173</td> 174</tr> 175<tr id="row10926540155513"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p119267409559"><a name="p119267409559"></a><a name="p119267409559"></a>int DisconnectAbility(const IAbilityConnection &conn)</p> 176</td> 177<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p592644085512"><a name="p592644085512"></a><a name="p592644085512"></a>Disconnects from a <strong id="b37531635205214"><a name="b37531635205214"></a><a name="b37531635205214"></a>Service</strong> ability.</p> 178</td> 179</tr> 180<tr id="row11926340145516"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p892614035513"><a name="p892614035513"></a><a name="p892614035513"></a>const char *GetBundleName()</p> 181</td> 182<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p99261040105511"><a name="p99261040105511"></a><a name="p99261040105511"></a>Obtains the bundle name of the application to which the ability belongs.</p> 183</td> 184</tr> 185<tr id="row7926440125519"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p4926114065519"><a name="p4926114065519"></a><a name="p4926114065519"></a>const char *GetSrcPath()</p> 186</td> 187<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p4926194055516"><a name="p4926194055516"></a><a name="p4926194055516"></a>Obtains the source code path of the ability.</p> 188</td> 189</tr> 190<tr id="row29261840115519"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1992604045519"><a name="p1992604045519"></a><a name="p1992604045519"></a>const char *GetDataPath()</p> 191</td> 192<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p109268403551"><a name="p109268403551"></a><a name="p109268403551"></a>Obtains the data path of the ability.</p> 193</td> 194</tr> 195<tr id="row29261940195516"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p159267407555"><a name="p159267407555"></a><a name="p159267407555"></a>int StartAbility(const Want *want)</p> 196</td> 197<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p1340210145179"><a name="p1340210145179"></a><a name="p1340210145179"></a>Starts an Ability. This function does not need to be used in applications developed based on <strong id="b12960101603119"><a name="b12960101603119"></a><a name="b12960101603119"></a>Ability</strong>.</p> 198</td> 199</tr> 200<tr id="row16926240155514"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1792617404558"><a name="p1792617404558"></a><a name="p1792617404558"></a>int ConnectAbility(const Want *want, const IAbilityConnection *conn, void *data);</p> 201</td> 202<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p1092612181812"><a name="p1092612181812"></a><a name="p1092612181812"></a>Connects to a Service ability based on the specified <strong id="b71516265816"><a name="b71516265816"></a><a name="b71516265816"></a>Want</strong> information. This function does not need to be used in applications developed based on <strong id="b12877235205716"><a name="b12877235205716"></a><a name="b12877235205716"></a>Ability</strong>.</p> 203</td> 204</tr> 205<tr id="row5927164010552"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p49271540165510"><a name="p49271540165510"></a><a name="p49271540165510"></a>int DisconnectAbility(const IAbilityConnection *conn);</p> 206</td> 207<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p1296152820189"><a name="p1296152820189"></a><a name="p1296152820189"></a>Disconnects from a Service ability. This function does not need to be used in applications developed based on <strong id="b1866210445818"><a name="b1866210445818"></a><a name="b1866210445818"></a>Ability</strong>.</p> 208</td> 209</tr> 210<tr id="row89271040135517"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p13927194011558"><a name="p13927194011558"></a><a name="p13927194011558"></a>int StopAbility(const Want *want)</p> 211</td> 212<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p7699548131819"><a name="p7699548131819"></a><a name="p7699548131819"></a>Stops a Service ability based on the specified <strong id="b53334211588"><a name="b53334211588"></a><a name="b53334211588"></a>Want</strong> information. This function does not need to be used in applications developed based on <strong id="b1466212716581"><a name="b1466212716581"></a><a name="b1466212716581"></a>Ability</strong>.</p> 213</td> 214</tr> 215<tr id="row1992764065516"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p192716406556"><a name="p192716406556"></a><a name="p192716406556"></a>void (*OnAbilityConnectDone)(ElementName *elementName, SvcIdentity *serviceSid, int resultCode, void *data)</p> 216</td> 217<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p0927940195510"><a name="p0927940195510"></a><a name="p0927940195510"></a>Called when a client is connected to a Service ability.</p> 218</td> 219</tr> 220<tr id="row7927134010559"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p692764095510"><a name="p692764095510"></a><a name="p692764095510"></a>void (*OnAbilityDisconnectDone)(ElementName *elementName, int resultCode, void *data)</p> 221</td> 222<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p18927124035516"><a name="p18927124035516"></a><a name="p18927124035516"></a>Called after all connections to a Service ability are disconnected.</p> 223</td> 224</tr> 225<tr id="row692784020556"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p17927104010557"><a name="p17927104010557"></a><a name="p17927104010557"></a>void PostTask(const Task& task)</p> 226</td> 227<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p13927940105516"><a name="p13927940105516"></a><a name="p13927940105516"></a>Posts a task to an asynchronous thread.</p> 228</td> 229</tr> 230<tr id="row392784013552"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1092794014555"><a name="p1092794014555"></a><a name="p1092794014555"></a>void PostQuit()</p> 231</td> 232<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p19281940185510"><a name="p19281940185510"></a><a name="p19281940185510"></a>Quits the event loop of the current thread.</p> 233</td> 234</tr> 235<tr id="row2928140145519"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p292813401555"><a name="p292813401555"></a><a name="p292813401555"></a>static AbilityEventHandler* GetCurrentHandler()</p> 236</td> 237<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p9928154012554"><a name="p9928154012554"></a><a name="p9928154012554"></a>Obtains the event handler of the current thread.</p> 238</td> 239</tr> 240<tr id="row15928174035513"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p1692824017551"><a name="p1692824017551"></a><a name="p1692824017551"></a>void Run()</p> 241</td> 242<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p592820401558"><a name="p592820401558"></a><a name="p592820401558"></a>Starts running the event loop of the current thread.</p> 243</td> 244</tr> 245<tr id="row15928174013554"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p17928440125516"><a name="p17928440125516"></a><a name="p17928440125516"></a>#define REGISTER_AA(className)</p> 246</td> 247<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p1892817404554"><a name="p1892817404554"></a><a name="p1892817404554"></a>Registers the class name of an <strong id="b102356594597"><a name="b102356594597"></a><a name="b102356594597"></a>Ability</strong> child class.</p> 248</td> 249</tr> 250<tr id="row17928640135519"><td class="cellrowborder" valign="top" width="53.849999999999994%" headers="mcps1.2.3.1.1 "><p id="p199281640125520"><a name="p199281640125520"></a><a name="p199281640125520"></a>#define REGISTER_AS(className)</p> 251</td> 252<td class="cellrowborder" valign="top" width="46.150000000000006%" headers="mcps1.2.3.1.2 "><p id="p1792811409556"><a name="p1792811409556"></a><a name="p1792811409556"></a>Registers the class name of an <strong id="b691819710011"><a name="b691819710011"></a><a name="b691819710011"></a>AbilitySlice</strong> child class.</p> 253</td> 254</tr> 255</tbody> 256</table> 257 258## How to Develop<a name="section10514141679"></a> 259 260### Creating a Service Ability<a name="section19921154214315"></a> 261 2621. Create the **MyServiceAbility** child class from **Ability** in **my\_service\_ability.h**. 263 264 ``` 265 class MyServiceAbility: public Ability { 266 protected: 267 void OnStart(const Want& want); 268 const SvcIdentity *OnConnect(const Want &want) override; 269 void MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) override; 270 }; 271 ``` 272 2732. Call the **REGISTER\_AA** macro to register the **ServiceAbility** class with the application framework so that the framework can instantiate the **MyServiceAbility** class you have created. 274 275 ``` 276 #include "my_service_ability.h" 277 278 REGISTER_AA(ServiceAbility) 279 280 void MyServiceAbility::OnStart(const Want& want) 281 { 282 printf("ServiceAbility::OnStart\n"); 283 Ability::OnStart(want); 284 } 285 286 const SvcIdentity *MyServiceAbility::OnConnect(const Want &want) 287 { 288 printf("ServiceAbility::OnConnect\n"); 289 return Ability::OnConnect(want); 290 } 291 292 void MyServiceAbility::MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) 293 { 294 printf("ServiceAbility::MsgHandle, funcId is %u\n", funcId); 295 int result = 0; 296 if (funcId == 0) { 297 result = IpcIoPopInt32(request) + IpcIoPopInt32(request); 298 } 299 // push data 300 IpcIoPushInt32(reply, result); 301 } 302 ``` 303 3043. Override the following lifecycle callbacks for Service abilities to implement your own logic for your Service ability. When overriding a lifecycle callback, you must call the corresponding function from the parent class. 305 - OnStart\(\) 306 307 This callback is invoked when a Service ability is being created to perform Service ability initialization operations that take a short time. This callback is invoked only once in the entire lifecycle of a Service ability. 308 309 ``` 310 void MyServiceAbility::OnStart(const Want& want) 311 { 312 printf("ServiceAbility::OnStart\n"); 313 Ability::OnStart(want); 314 } 315 ``` 316 317 - OnConnect\(\) 318 319 This callback is invoked when another ability is connected to the Service ability. This callback returns an **SvcIdentity** object for the other ability to interact with the Service ability. 320 321 ``` 322 const SvcIdentity *MyServiceAbility::OnConnect(const Want &want) 323 { 324 printf("ServiceAbility::OnConnect\n"); 325 return Ability::OnConnect(want); 326 } 327 ``` 328 329 - OnDisconnect\(\) 330 331 This callback is invoked when another ability is disconnected from the Service ability. 332 333 - OnStop\(\) 334 335 This callback is invoked when a Service ability is destroyed. You should override this callback for your Service ability to clear its resources, such as threads and registered listeners. 336 3374. Override the message handling function. 338 339 The **MsgHandle** function is used by Service abilities to handle messages sent from clients. **funcId** indicates the type of the message sent from the client, and **request** indicates the pointer to the serialized request parameters sent from the client. If you want to send the result back after the message is handled, serialize the result and write it into **reply**. 340 341 ``` 342 void ServiceAbility::MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) 343 { 344 printf("ServiceAbility::MsgHandle, funcId is %d\n", funcId); 345 int result = 0; 346 if (funcId == PLUS) { 347 result = IpcIoPopInt32(request) + IpcIoPopInt32(request); 348 } 349 // push data 350 IpcIoPushInt32(reply, result); 351 } 352 ``` 353 3545. Register a Service ability. 355 356 Declare your Service ability in the **config.json** file by setting its **type** attribute to **service**. 357 358 ``` 359 "abilities": [{ 360 "name": "ServiceAbility", 361 "icon": "res/drawable/phone.png", 362 "label": "test app 2", 363 "launchType": "standard", 364 "type": "service", 365 "visible": true 366 } 367 ] 368 ``` 369 3706. Start a Service ability. 371 - The **Ability** class provides the **StartAbility\(\)** function to start another ability. You can pass a **Want** object to this function to start a Service ability. 372 373 You can use the **SetWantElement\(\)** function provided in the **AbilityKit** to set information about the target Service ability to start. The **element** parameter of the **SetWantElement\(\)** function indicates the **ElementName** structure that contains the bundle name and target ability name required for starting an ability. 374 375 ``` 376 { 377 Want want = { nullptr }; 378 ElementName element = { nullptr }; 379 SetElementBundleName(&element, "com.company.appname"); 380 SetElementAbilityName(&element, "ServiceAbility"); 381 SetWantElement(&want, element); 382 StartAbility(want); 383 ClearElement(&element); 384 ClearWant(&want); 385 } 386 ``` 387 388 The **StartAbility\(\)** function is executed immediately. If the Service ability is not running while the function is called, the system invokes **OnStart\(\)** first. 389 390 - Stops a Service ability. 391 392 Once created, the Service ability keeps running in the background. You can call **StopAbility\(\)** to stop the Service ability. 393 3947. Connect to a Service ability. 395 - If you need to connect a Service ability to a Page ability or to a Service ability in another application, you should first create a Service ability for connection. A Service ability allows other abilities to connect to it through **ConnectAbility\(\)** by passing a **Want** object that contains information about the target Service ability to the function. You can implement callbacks in **IAbilityConnection** to be invoked when a Service ability is connected or disconnected. The **OnAbilityConnectDone\(\)** callback is invoked when an ability is connected, and **OnAbilityDisconnectDone\(\)** is invoked when an ability is disconnected. 396 397 ``` 398 { 399 // Create an IAbilityConnection object and implement the two callbacks. 400 IAbilityConnection abilityConnection = new IAbilityConnection(); 401 abilityConnection->OnAbilityConnectDone = OnAbilityConnectDone; 402 abilityConnection->OnAbilityDisconnectDone = OnAbilityDisconnectDone; 403 404 void OnAbilityConnectDone(ElementName *elementName, SvcIdentity *serviceSid, 405 int resultCode, void *data) 406 { 407 if (resultCode != 0) { 408 return; 409 } 410 // Push data. 411 IpcIo request; 412 char dataBuffer[IPC_IO_DATA_MAX]; 413 IpcIoInit(&request, dataBuffer, IPC_IO_DATA_MAX, 0); 414 IpcIoPushInt32(&request, 10); 415 IpcIoPushInt32(&request, 6); 416 417 // Send and receive the reply. 418 IpcIo reply; 419 uintptr_t ptr = 0; 420 if (Transact(nullptr, *serviceSid, 0, &request, &reply, 421 LITEIPC_FLAG_DEFAULT, &ptr) != LITEIPC_OK) { 422 printf("transact error\n"); 423 return; 424 } 425 int result = IpcIoPopInt32(&reply); 426 printf("execute add method, result is %d\n", result); 427 if (ptr != 0) { 428 FreeBuffer(nullptr, reinterpret_cast<void *>(ptr)); 429 } 430 } 431 432 void OnAbilityDisconnectDone(ElementName *elementName, 433 int resultCode, void *data) 434 { 435 printf("elementName is %s, %s\n", 436 elementName->bundleName, elementName->abilityName); 437 } 438 } 439 ``` 440 441 - The following sample code snippet shows how to initiate ability connection and disconnection: 442 443 ``` 444 { 445 // Connect an ability to a specified Service ability. 446 Want want = { nullptr }; 447 ElementName element = { nullptr }; 448 SetElementBundleName(&element, "com.company.appname"); 449 SetElementAbilityName(&element, "ServiceAbility"); 450 SetWantElement(&want, element); 451 ConnectAbility(want, *abilityConnection, this); 452 453 // Disconnect from a Service ability. 454 DisconnectAbility(*abilityConnection); 455 } 456 ``` 457 458 459 460### Development Guidelines on Bundle Management<a name="section1724016743217"></a> 461 462**Installing an Application** 463 464The installation API can only be used by built-in system applications. Applications can be installed in either of the following paths: 465 466- Default installation directory **/storage/app/** in the system 467- Particular directory on the external storage, for example, a microSD card 468 469You can specify the installation path when creating an **InstallParam** instance. To install the application in the **/storage/app/** directory, set the **installLocation** member variable in the **InstallParam** instance to **INSTALL\_LOCATION\_INTERNAL\_ONLY**. To install the application in the **/sdcard/app/** directory of the external storage, set **installLocation** to **INSTALL\_LOCATION\_PREFER\_EXTERNAL**. The application installation process is asynchronous, and a semaphore-like mechanism is required to ensure that the installation callback can be executed. 470 471The procedure for installing an application is as follows \(the system directory is used as an example\): 472 4731. Place the signed HAP file in a specified directory. 4742. Create an **InstallParam** instance and define the semaphore. 475 476 ``` 477 InstallParam installParam = { 478 .installLocation = INSTALL_LOCATION_INTERNAL_ONLY, // Install the application in the system directory. 479 .keepData = false 480 }; 481 static sem_t g_sem; 482 ``` 483 4843. Define the callback function. 485 486 ``` 487 static void InstallCallback(const uint8_t resultCode, const void *resultMessage) 488 { 489 std::string strMessage = reinterpret_cast<const char *>(resultMessage); 490 if (!strMessage.empty()) { 491 printf("install resultMessage is %s, %d\n", strMessage.c_str(),resultCode); 492 } 493 sem_post(&g_sem); 494 } 495 ``` 496 4974. Call the **Install** function. 498 499 ``` 500 const uint32_t WAIT_TIMEOUT = 30; 501 sem_init(&g_sem, 0, 0); 502 std::string installPath = "/storage/bundle/demo.hap"; // Specify the path where the HAP file is stored. 503 bool result = Install(installPath.c_str(), &installParam, InstallCallback); 504 struct timespec ts = {}; 505 clock_gettime(CLOCK_REALTIME, &ts); 506 ts.tv_sec += WAIT_TIMEOUT; // Release the semaphore upon timeout. 507 sem_timedwait(&g_sem, &ts); 508 ``` 509 510 511**Uninstalling an Application** 512 513When uninstalling an application, you can specify whether to retain application data using the **keepData** member variable in the created **InstallParam** instance. If **keepData** is set to **true**, the application data will be retained after the application is uninstalled. If the variable is set to **false**, the application data will be removed during application installation. 514 5151. Create an **InstallParam** instance and define the semaphore. 516 517 ``` 518 static sem_t g_sem; 519 InstallParam installParam = { 520 .installLocation = 1, 521 .keepData = false // Remove application data. 522 }; 523 ``` 524 5252. Define the callback function. 526 527 ``` 528 static void UninstallCallback(const uint8_t resultCode, const void *resultMessage) 529 { 530 std::string strMessage = reinterpret_cast<const char *>(resultMessage); 531 if (!strMessage.empty()) { 532 printf("uninstall resultMessage is %s\n", strMessage.c_str()); 533 g_resultMessage = strMessage; 534 } 535 g_resultCode = resultCode; 536 sem_post(&g_sem); 537 } 538 ``` 539 5403. Call the **Uninstall** function. 541 542 ``` 543 sem_init(&g_sem, 0, 0); 544 const uint32_t WAIT_TIMEOUT = 30; 545 std::string BUNDLE_NAME = "com.huawei.demo"; // Bundle name of the application to be uninstalled 546 Uninstall(BUNDLE_NAME.c_str(), &installParam, UninstallCallback); 547 struct timespec ts = {}; 548 clock_gettime(CLOCK_REALTIME, &ts); 549 ts.tv_sec += WAIT_TIMEOUT; 550 sem_timedwait(&g_sem, &ts); 551 ``` 552 553 554**Querying Bundle Information About an Installed Application** 555 556You can use the **GetBundleInfo** function provided by **BundleManager** to query the bundle information about installed applications in the system. 557 5581. Create and initialize a **BundleInfo** object. 559 560 ``` 561 BundleInfo bundleInfo; 562 (void) memset_s(&bundleInfo, sizeof(BundleInfo), 0, sizeof(BundleInfo)); 563 ``` 564 5652. Call **GetBundleInfo** to obtain bundle information about a specified application. The **bundleName** parameter indicates the pointer to the application bundle name, and the **flags** parameter specifies whether the obtained **BundleInfo** object can contain **AbilityInfo**. 566 567 ``` 568 std::string BUNDLE_NAME = "com.huawei.demo"; 569 uint8_t ret = GetBundleInfo(BUNDLE_NAME.c_str(), 1, &bundleInfo); // When flags is set to 1, the obtained BundleInfo object contains AbilityInfo. 570 ``` 571 5723. After you finish using the obtained **BundleInfo** object, clear the memory space occupied by the object in a timely manner to prevent memory leakage. 573 574 ``` 575 ClearBundleInfo(&bundleInfo); 576 ``` 577 578 579### Packing a HAP File<a name="section171771212328"></a> 580 581The packing tool is generally integrated into the development tool or IDE, and you rarely have the occasion to use it directly. This section is provided for you to have a general knowledge of the packing tool. The JAR file of the packing tool is stored in the **developtools/packing\_tool/jar** directory of the open-source code. 582 583- CLI command parameters for packing a HAP file 584 585 **Table 2** Description of resource files required for packing 586 587 <a name="table2151102833212"></a> 588 <table><thead align="left"><tr id="row314812893218"><th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.1"><p id="p1614732812320"><a name="p1614732812320"></a><a name="p1614732812320"></a>Command Parameter</p> 589 </th> 590 <th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.2"><p id="p214722819322"><a name="p214722819322"></a><a name="p214722819322"></a>Resource File</p> 591 </th> 592 <th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.3"><p id="p214714286324"><a name="p214714286324"></a><a name="p214714286324"></a>Description</p> 593 </th> 594 <th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.4"><p id="p1014712863211"><a name="p1014712863211"></a><a name="p1014712863211"></a>Initial Value Allowed</p> 595 </th> 596 </tr> 597 </thead> 598 <tbody><tr id="row614812289322"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p16148182853216"><a name="p16148182853216"></a><a name="p16148182853216"></a>--mode</p> 599 </td> 600 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p5148162814328"><a name="p5148162814328"></a><a name="p5148162814328"></a>-</p> 601 </td> 602 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p11481228143215"><a name="p11481228143215"></a><a name="p11481228143215"></a>This parameter is set to <strong id="b5192781718"><a name="b5192781718"></a><a name="b5192781718"></a>hap</strong> for packing the resource files into a HAP file.</p> 603 </td> 604 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p11148132811325"><a name="p11148132811325"></a><a name="p11148132811325"></a>No</p> 605 </td> 606 </tr> 607 <tr id="row81486283327"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p6148132833215"><a name="p6148132833215"></a><a name="p6148132833215"></a>--json-path</p> 608 </td> 609 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p214810286325"><a name="p214810286325"></a><a name="p214810286325"></a>Configuration file <strong id="b88502557175"><a name="b88502557175"></a><a name="b88502557175"></a>config.json</strong></p> 610 </td> 611 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p514802823216"><a name="p514802823216"></a><a name="p514802823216"></a>-</p> 612 </td> 613 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p4148182813326"><a name="p4148182813326"></a><a name="p4148182813326"></a>No</p> 614 </td> 615 </tr> 616 <tr id="row1214917281322"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p171497285322"><a name="p171497285322"></a><a name="p171497285322"></a>--resources-path</p> 617 </td> 618 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p414914286320"><a name="p414914286320"></a><a name="p414914286320"></a>Resource file <strong id="b62311484202"><a name="b62311484202"></a><a name="b62311484202"></a>resources</strong></p> 619 </td> 620 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p41492286324"><a name="p41492286324"></a><a name="p41492286324"></a>-</p> 621 </td> 622 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p1114922812327"><a name="p1114922812327"></a><a name="p1114922812327"></a>Yes</p> 623 </td> 624 </tr> 625 <tr id="row14149122817322"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p11149528173218"><a name="p11149528173218"></a><a name="p11149528173218"></a>--assets-path</p> 626 </td> 627 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p314918286324"><a name="p314918286324"></a><a name="p314918286324"></a>Resource file <strong id="b847745320206"><a name="b847745320206"></a><a name="b847745320206"></a>assets</strong></p> 628 </td> 629 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p1414916284327"><a name="p1414916284327"></a><a name="p1414916284327"></a>-</p> 630 </td> 631 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p9149122817324"><a name="p9149122817324"></a><a name="p9149122817324"></a>Yes</p> 632 </td> 633 </tr> 634 <tr id="row41501728193219"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p514918280325"><a name="p514918280325"></a><a name="p514918280325"></a>--lib-path</p> 635 </td> 636 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p16149162823212"><a name="p16149162823212"></a><a name="p16149162823212"></a>Dependent library file</p> 637 </td> 638 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p12149122853216"><a name="p12149122853216"></a><a name="p12149122853216"></a>-</p> 639 </td> 640 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p614962853217"><a name="p614962853217"></a><a name="p614962853217"></a>Yes</p> 641 </td> 642 </tr> 643 <tr id="row131501928183212"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p4150122833213"><a name="p4150122833213"></a><a name="p4150122833213"></a>--shared-libs-path</p> 644 </td> 645 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p15150112814322"><a name="p15150112814322"></a><a name="p15150112814322"></a>Shared library file</p> 646 </td> 647 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p20150128113212"><a name="p20150128113212"></a><a name="p20150128113212"></a>The shared library is used by system applications in special cases.</p> 648 </td> 649 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p181501928183214"><a name="p181501928183214"></a><a name="p181501928183214"></a>Yes</p> 650 </td> 651 </tr> 652 <tr id="row10150142812329"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p1015011286320"><a name="p1015011286320"></a><a name="p1015011286320"></a>--ability-so-path</p> 653 </td> 654 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p6150728123214"><a name="p6150728123214"></a><a name="p6150728123214"></a>SO file providing main functionality</p> 655 </td> 656 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p16150192813323"><a name="p16150192813323"></a><a name="p16150192813323"></a>-</p> 657 </td> 658 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p1315052811325"><a name="p1315052811325"></a><a name="p1315052811325"></a>Yes</p> 659 </td> 660 </tr> 661 <tr id="row51519280321"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p315092813214"><a name="p315092813214"></a><a name="p315092813214"></a>--index-path</p> 662 </td> 663 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p1115012813325"><a name="p1115012813325"></a><a name="p1115012813325"></a>Resource index</p> 664 </td> 665 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p111501028123220"><a name="p111501028123220"></a><a name="p111501028123220"></a>The resource index file is generated by the resource generation tool and integrated by the resource pipeline.</p> 666 </td> 667 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p1115122811326"><a name="p1115122811326"></a><a name="p1115122811326"></a>Yes</p> 668 </td> 669 </tr> 670 <tr id="row91511928203211"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p0151328173211"><a name="p0151328173211"></a><a name="p0151328173211"></a>--out-path</p> 671 </td> 672 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p215112833214"><a name="p215112833214"></a><a name="p215112833214"></a>-</p> 673 </td> 674 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p11151152833217"><a name="p11151152833217"></a><a name="p11151152833217"></a>This parameter indicates the output path of the generated HAP file. The default value is the current directory.</p> 675 </td> 676 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p1815110281328"><a name="p1815110281328"></a><a name="p1815110281328"></a>Yes</p> 677 </td> 678 </tr> 679 <tr id="row4151162812329"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p1015112280329"><a name="p1015112280329"></a><a name="p1015112280329"></a>--force</p> 680 </td> 681 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p2151128133219"><a name="p2151128133219"></a><a name="p2151128133219"></a>-</p> 682 </td> 683 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p9151928183218"><a name="p9151928183218"></a><a name="p9151928183218"></a>This parameter specifies whether to overwrite an existing file with the same name. The default value is <strong id="b867781662412"><a name="b867781662412"></a><a name="b867781662412"></a>false</strong>.</p> 684 </td> 685 <td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p171511728143217"><a name="p171511728143217"></a><a name="p171511728143217"></a>Yes</p> 686 </td> 687 </tr> 688 </tbody> 689 </table> 690 691- Example HAP File Structure 692 - Development view 693 694  695 696 - Compilation view 697 698  699 700 - Run the following commands to pack a HAP file using the packing tool. 701 702  703 704 ``` 705 $ java -jar hmos_app_packing_tool.jar --mode hap --json-path ./config.json --assets-path ./assets/ --ability-so-path ./libentry.so --index-path ./resources.index --out-path out/entry.hap --force true 706 ``` 707 708 709 710