# interface_sdk-js **Repository Path**: rtos_yuan/interface_sdk-js ## Basic Information - **Project Name**: interface_sdk-js - **Description**: 暂无描述 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: https://gitee.com/openharmony/interface_sdk-js - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 4354 - **Created**: 2025-03-19 - **Last Updated**: 2025-04-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ArkTS演进 HelloWorld工程编译运行常见问题 ## 0X00、更新日志 ### 0410 10:30更新: 如果使用0328分支的SDK,需要临时做如下修改,等新版本IDE外发后,不再需要修改: - 1、helloworld工程根目录build-profile.json5中compileSdkVersion字段改为18 - 2、替换的OpenHarmonySDK下的目录17改为18,再替换sdk - 3、替换DevEcoStudio\tools\hvigor,新hvigor下载地址:https://gitee.com/laoji-fuli/command-line-tools/tree/test/hvigor。替换hvigor后,需要重新执行下文的powershell脚本。 - 4、关闭hvigor的daemon守护进程 > tips: 因涉及频繁替换SDK或hvigor工具,daemon守护进程会缓存一部分工具信息到内存中,导致替换不生效。所以建议关闭daemon再使用。File -> Setting,搜索hvigor,取消勾选:Enable the Daemon for tasks。 ## 0x01、DevEco Studio相关问题 ### 1.1 如何获取DevEco Studio 加入蓝色WeLink群,在群空间里获取DevEco Studio安装文件。获取的DevEco Studio属于OpenHarmony版本的,需要配套使用OpenHarmony工程。 ![welink](./images/welinkgroup.png) 完成DevEco Studio安装后,需要执行如下脚本,解决当前版本的已知Bug。 ### 1.2 执行脚本解决DevEco Studio的问题(临时) 修改替换DevEco Studio的安装目录,然后打开PowerShell执行。如果遇到`【Windows】powershell无法加载文件 xx.ps1,因为在此系统上禁止运行脚本`,可以执行命令`Set-ExecutionPolicy RemoteSigned`解决。 ``` #文件类型 .ps1 # 这里填写自己的IDE的安装目录 $ide_path="D:\DevEcoStudio" $hvigor_path=$ide_path + '\tools\hvigor' $filePath = $hvigor_path + "\hvigor-ohos-plugin\src\const\common-const.js" $replaceString = 'exports\.LanguageConst=\{DEFAULT:"1\.1",ARKTS1_0:"1\.0",ARKTS1_1:"1\.1",ARKTS1_2:"1\.2",ARKTS_HYBRID:"hybrid"\};' $searchString = 'exports.LanguageConst={DEFAULT:"ArkTS1.1",ARKTS1_0:"ArkTS1.0",ARKTS1_1:"ArkTS1.1",ARKTS1_2:"ArkTS1.2",ARKTS_HYBRID:"hybrid"};' echo $filePath # 读取文件内容 $content = Get-Content -Path $filePath -Raw # 使用正则表达式进行查找和替换 $newContent = [regex]::Replace($content, $searchString, $replaceString) # 将修改后的内容写回文件 Set-Content -Path $filePath -Value $newContent Write-Output "替换完成" $filePath = $hvigor_path + "\hvigor-ohos-plugin\src\tasks\process-profile.js" $searchString = 'language' $replaceString = 'codeLanguage' echo $filePath # 读取文件内容 $content = Get-Content -Path $filePath -Raw # 使用正则表达式进行查找和替换 $newContent = [regex]::Replace($content, $searchString, $replaceString) # 将修改后的内容写回文件 Set-Content -Path $filePath -Value $newContent Write-Output "替换完成" $filePath = $hvigor_path + "\hvigor-ohos-plugin\src\tasks\process-profile.js" $searchString = 'processDependencyHarAbility\(e\)\{' $replaceString = 'processDependencyHarAbility(e){ if (this.targetService.getSelfArkTSVersion() === common_const_js_1.ArkTSVersionConst.ARKTS1_2) {e.module.codeLanguage = common_const_js_1.LanguageConst.ARKTS1_2};' echo $filePath # 读取文件内容 $content = Get-Content -Path $filePath -Raw # 使用正则表达式进行查找和替换 $newContent = [regex]::Replace($content, $searchString, $replaceString) # 将修改后的内容写回文件 Set-Content -Path $filePath -Value $newContent Write-Output "替换完成" ``` ## 0x02、日构建SDK相关问题 ### 2.1、如何获取新版本日构建SDK 访问网站[https://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist](https://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist),做如下设置: - 项目 选择 openharmony - 分支 选择 OpenHarmony_feature_20250328 - 日期 选择 今天 然后选择滚动构建,流水线名称选择`ohos-sdk-public_feature`或`ohos-sdk-public_0328`类似的名称,点击版本下载地址列的下载链接,选择全量包进行下载。 ![dailylist](./images/dailylist.jpg) ### 2.2、更新OpenHarmony版本DevEco Studio中的SDK 进入压缩包`ohos-sdk-public_feature\ohos-sdk\windows`,把如下4个文件复制到目录`D:\OpenHarmony\Sdk\17`,并解压下面4个文件,必须使用`Sdk\17`这样的目录结构。 > 对于0328分支,必须使用`Sdk\18`这样的目录结构,否则会让配置代理下载SDK。 - ets-windows-x64-5.0.2.5-Canary1.zip - js-windows-x64-5.0.2.5-Canary1.zip - native-windows-x64-5.0.2.5-Canary1.zip - previewer-windows-x64-5.0.2.5-Canary1.zip - toolchains-windows-x64-5.0.2.5-Canary1.zip 解压后目录结构如下所示: ![sdk_dir](./images/sdk_dir.png) ### 2.3、更新HarmonyOS版本DevEco Studio中的SDK 进入压缩包`ohos-sdk-public_feature\ohos-sdk\windows`,解压出`ets-windows-x64-5.0.2.5-Canary1.zip`文件,解压得到ets文件夹,该文件夹下面包含ets1.1和ets1.2。把ets文件夹替换到`DevEcoStudio\sdk\default\openharmony\ets`即可。 ### 2.4 如何自己编译SDK 执行编译命令: ``` ./build.sh --product-name ohos-sdk --ccache ``` **结果输出:** ``` out/sdk/packages/ohos-sdk/ ``` ohos-sdk模块配置: ``` build/ohos/sdk/ohos_sdk_description_std.json ``` 更多信息参考: - https://gitee.com/openharmony/build - https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-compile-guide.md ### 2.5、如何开发调试声明文件 [https://gitee.com/openharmony/interface_sdk-js/tree/OpenHarmony_feature_20241108/](https://gitee.com/openharmony/interface_sdk-js/tree/OpenHarmony_feature_20241108/)属于源码态的SDK,在DevEco Studio使用的属于发布态的SDK,内容和结构会有差异。 对于ArkTS 1.2演进项目,API目录位置在:`ets\ets1.2\api`。 在调试修改时,可以编辑源码态,自己编译出SDK替换;也可以直接先修改发布态的SDK,调试成功后,再同步到源码态,然后提交到代码仓。 ## 0x03、Hello World工程相关问题 ### 3.1、HelloWorld工程 DevEco Studio支持OpenHarmony工程和HarmonyOS工程,区别就是使用的SDK是否包含hms闭源接口。工程配置文件也有不同,[可以参考PR](https://gitee.com/openharmony/applications_app_samples/pulls/5681/files)。 OpenHarmony版本的HelloWorld工程:[https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony_feature_20250328/code/HelloWorld](https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony_feature_20250328/code/HelloWorld) HarmonyOS版本的HelloWorld工程:[https://gitee.com/rtos_yuan/interface_sdk-js/tree/master/Codes/HelloWorld](https://gitee.com/rtos_yuan/interface_sdk-js/tree/master/Codes/HelloWorld) ### 3.2、如何编译运行HelloWorld工程 访问链接[https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony_feature_20241108/code/HelloWorld](https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony_feature_20241108/code/HelloWorld)下载HelloWorld工程。该工程为OpenHarmony版本的HelloWorld工程。 使用DevEco Studio打开下载的HelloWorld工程,选择`File-Settings-OpenHarmony SDK`,编辑,选择下载好的SDK,如下图: ![Sdk_location](./images/Sdk_location.jpg) 然后,在`File-Project Structure-Signing Configs`设置签名信息。连接设备,就可以编译运行了。 ![sign_config](./images/sign_config.jpg)