modify IntelliJ plugin docs

Signed-off-by: gou-jingjing <goujingjing@kaihong.com>
This commit is contained in:
gou-jingjing 2024-01-03 14:05:10 +08:00
parent 6d79c58c5c
commit 90a3a209ad
28 changed files with 327 additions and 78 deletions

View File

@ -150,6 +150,7 @@ serviceCode/NodeISayHello.cpp
```
[
{
"genPath": "/home/kaihong1/napi/myCommitNapiTest/generatorCode",
"includeName": "../serviceCode/NodeISayHello.h",
"cppName": "../serviceCode/NodeISayHello.cpp",
"interfaceName": "funcTest",
@ -161,6 +162,8 @@ serviceCode/NodeISayHello.cpp
cfg.json是一个数组每一项配置对应一个方法的调用需要对多少方法进行调用就配置多少项其中
"genPath": 生成框架代码路径,用户的业务代码相对于该路径配置,如:"/home/kaihong1/napi/myCommitNapiTest/generatorCode"
"includeName": 引入的业务代码.h文件相对路径, 如:"../serviceCode/NodeISayHello.h",
"cppName": 引入的业务代码.cpp文件相对路径, 如:"../serviceCode/NodeISayHello.cpp",
@ -215,6 +218,7 @@ cfg.json是一个数组每一项配置对应一个方法的调用需要对
```
[
{
"genPath": "E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode",
"includeName": "../serviceCode/NodeISayHello.h",
"cppName": "../serviceCode/NodeISayHello.cpp",
"interfaceName": "funcTest",
@ -226,6 +230,8 @@ cfg.json是一个数组每一项配置对应一个方法的调用需要对
cfg.json是一个数组每一项配置对应一个方法的调用需要对多少方法进行调用就配置多少项其中
"genPath": 生成框架代码路径,用户的业务代码相对于该路径配置,如:"E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode"
"includeName": 引入的业务代码.h文件相对路径, 如:"../serviceCode/NodeISayHello.h",
"cppName": 引入的业务代码.cpp文件相对路径, 如:"../serviceCode/NodeISayHello.cpp",

View File

@ -1,23 +1,27 @@
[
{
"genPath": "E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode",
"includeName": "../serviceCode/NodeISayHello.h",
"cppName": "../serviceCode/NodeISayHello.cpp",
"interfaceName": "NodeISayHello::sayHello",
"serviceCode": "napitest::NodeISayHello *p = new napitest::NodeISayHello();\n p->sayHello(from, to, sayType);\n delete p;"
},
{
"genPath": "E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode",
"includeName": "../serviceCode/NodeISayHello.h",
"cppName": "../serviceCode/NodeISayHello.cpp",
"interfaceName": "NodeISayHello::sayHi",
"serviceCode": "napitest::NodeISayHello *p = new napitest::NodeISayHello();\n p->sayHi(from, to, sayType);\n delete p;"
},
{
"genPath": "E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode",
"includeName": "../serviceCode/NodeISayHello.h",
"cppName": "../serviceCode/NodeISayHello.cpp",
"interfaceName": "funcTest",
"serviceCode": "out = napitest::funcTest(v);"
},
{
"genPath": "E:\\napi_aboutTest\\testcase_napi_intellijPlugin\\generatorCode",
"includeName": "../serviceCode/NodeISayHello.h",
"cppName": "../serviceCode/NodeISayHello.cpp",
"interfaceName": "NodeISayHello::sayHelloWithResponse",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

@ -39,10 +39,18 @@ NAPI框架代码生成工具它可以根据用户指定路径下的ts(typescr
[DevEco Studio上使用的IntelliJ插件下载链接](https://plugins.jetbrains.com/plugin/19593-napi-generator/versions)
// 此处更新1.0.3版本图片
![](../figures/pic-napi_jar_download.png)
使用谷歌浏览器时:
// 更新图片
![](../figures/picGoogle-napi_jar_download.png)
具体的工具使用步骤,可以左键单击以下链接了解:
@ -53,38 +61,40 @@ NAPI框架代码生成工具它可以根据用户指定路径下的ts(typescr
根据使用者指定的typescript文件工具会输出NAPI框架代码、业务代码框架、GN脚本等文件。
为了方便使用者快速上手工具可供测试的typescript文件存放在以下路径
为了方便使用者快速上手工具可供测试的typescript文件存放在DevEco Studio中以下路径:
```
napi_IntelliJ_plugin
entry/src
```
在window环境下的根据输入文件@ohos.napitest.d.ts和basic.d.ts生成的输出文件如下所示
![](../figures/pic-d-ts-transition.png)
其中生成的"napitest.h"文件,定义了框架代码的接口,如下所示:
![](../figures/pic-d-ts-dev_transition.png)
```c++
#include "napitest.h"
namespace napitest {
bool func1(std::string& v1, std::string& out)
{
// TODO
return true;
}
}
其中CMakeLists.txt为编译构建需要的文件cfg.json为生成的业务代码配置文件若用户不进行业务代码配置则不会生成该文件生成的"napitest.h"文件,定义了框架代码的接口,生成的部分接口如下所示:
```
...
class NodeISayHello {
public:
bool addSayHelloListener(NodeISayHelloListener& listener);
static NodeISayHelloListener listener_;
bool removeSayHelloListener(NodeISayHelloListener& listener);
bool registerCallbackfunc();
// 供业务调用的回调接口
void CallbackfuncCallback(NUMBER_TYPE_2& wid);
### 集成方法
为了实现工具生成的接口被其他子系统或者应用调用需将生成的代码编译集成到OpenHarmony系统中编译生成动态库。
把工具的生成代码集成到OpenHarmony的具体操作步骤可以左键单击以下链接了解
[生成代码集成到OpenHarmony的方法](https://gitee.com/openharmony/napi_generator/blob/master/docs/ENSEMBLE_METHOD_ZH.md)
bool unRegisterCallbackfunc();
bool sayHello(std::string& from, std::string& to, NUMBER_TYPE_9& sayType);
bool sayHi(std::string& from, std::string& to, NUMBER_TYPE_10& sayType);
bool sayHelloWithResponse(std::string& from, std::string& to, NUMBER_TYPE_11& sayType, uint32_t& outErrCode, AUTO_INTERFACE_5& out);
static AUTO_INTERFACE_5 auto_interface_5OutRes;
void auto_interface_5SetCbValue(NUMBER_TYPE_6 result, std::string errMsg, std::string response);
};
...
```
## 开发说明

View File

@ -45,13 +45,28 @@ Project Settings > Modules 新建Modules。点击上方“-”删除原有的Mod
![](../../../figures/IntelliJ_env_Proj_Module_New.png)
7.配置Content root
Content root选择~/napi_generator/napi_IntelliJ_plugin文件夹module name填写generator。点击Finish若出现提示已存在是否覆盖的提示请点“Yes”完成配置。
Content root选择~/napi_generator/napi_IntelliJ_plugin文件夹module name填写napi_generator。点击Finish若出现提示已存在是否覆盖的提示请点“Yes”完成配置。
![](../../../figures/IntelliJ_env_module_root.png)
8.Modules配置完成后若在SDKs中无相应JDK和Plugin SDK,请点击+号分别添加 Add Java JDK和Add Intellij PlantForm Plugin SDK,Java JDK为java11的安装目录Plugin SDK为 IDEA Community 2021.3.3的安装目录。
![](../../../figures/IntelliJ_env_config_SDKs.png)
9.若完成以上步骤配置点击OK完成配置。Rebuild项目若IDEA不能点击右上角的运行点击Plugin后下三角选择Edit Configurations...选项Run/Debug Configurations框中Use classpath of moudle选择generator点击ok等待安装完成。
9.配置Librariesnapi 1.0.3版本以及之后版本才需要配置依赖,之前的版本可跳过此步骤)
配置依赖原因由于IntellIj插件市场兼容性问题原使用的json库与新版本的IDE不兼容因此使用新的json库解决兼容性问题新的json库需要从Maven仓库下载并将依赖配置到工程中。
步骤:点击"+",选择"From Maven..."在搜索框搜索依赖的jar包com.alibaba.fastjson2:fastjson2:2.0.42,勾选"Download to"并点击OK将依赖下载至工程目录下的lib文件夹点击"Choose Modules"中的OK。
![](../../../figures/IntelliJ_env_config_libs.png)
![](../../../figures/IntelliJ_env_config_libs_download.png)
![](../../../figures/IntelliJ_env_config_libs_choose_module.png)
![](../../../figures/IntelliJ_env_config_libs_check.png)
10.若完成以上步骤配置点击OK完成配置。Rebuild项目若IDEA不能点击右上角的运行点击Plugin后下三角选择Edit Configurations...选项Run/Debug Configurations框中Use classpath of moudle选择napi_generator点击ok等待安装完成。
![](../../../figures/IntelliJ_env_configurations.png)
@ -61,14 +76,20 @@ Content root选择~/napi_generator/napi_IntelliJ_plugin文件夹module name
![](../../../figures/IntelliJ_env_built_pro.png)
11.在IDEA Community中依次点击Build>Prepare All Plugin Modules for development"然后在Select Modules框中点击okjar包生成完成后在工具右下角提示jar包生成成功且包含jar包存放位置。
11.在IDEA Community中依次点击Build>Prepare All Plugin Modules for development"然后在Select Modules框中点击okjar/zip包生成完成后在工具右下角提示jar/zip包生成成功且包含jar/zip包存放位置。
![](../../../figures/IntelliJ_env_built_jar.png)
![](../../../figures/IntelliJ_env_select_moudles.png)
1.0.3版本之前生成的包为.jar格式1.0.3以及之后版本生成的版本为.zip格式(由于新增了lib依赖com.alibaba.fastjson2:fastjson2:2.0.42,因此最终的插件包为.zip格式)。
![](../../../figures/IntelliJ_env_built_jar_success.png)
![](../../../figures/IntelliJ_env_built_zip_success.png)
## 工具测试
进行工具二次开发后本地可进行单元测试、story特性测试确保工具的可用性。左键单击以下链接了解详情

View File

@ -5,62 +5,206 @@
## 准备
1. 待转换的@ohos.napitest.d.ts文件如下
### 待转换的ts文件用例
待转换的@ohos.napitest.d.ts文件如下
[@ohos.napitest.d.ts](https://gitee.com/openharmony/napi_generator/blob/master/examples/ts/@ohos.napitest.d.ts)
### 业务代码用例
业务代码用例如下:
serviceCode/NodeISayHello.h
[NodeISayHello.h](https://gitee.com/openharmony/napi_generator/blob/master/examples/pluginCase/serviceCode/NodeISayHello.h)
serviceCode/NodeISayHello.cpp
[NodeISayHello.cpp](https://gitee.com/openharmony/napi_generator/blob/master/examples/pluginCase/serviceCode/NodeISayHello.cpp)
### 测试应用用例
在DevEco Studio中增加调用napi方法的测试用例。其中修改index.js文件内容如下
[Index.ets](https://gitee.com/openharmony/napi_generator/blob/master/examples/pluginCase/Index.ets)
1.定义回调:
1.1 定义object回调
```
import {AsyncCallback} from './basic';
declare namespace napitest {
function fun1(v1: string): string;
class NodeISayHelloListenerImpl {
onSayHelloStart(info: object) {
console.log('napiTestDemo ----onSayHelloStart', info);
AppStorage.SetOrCreate("textInfoStart", JSON.stringify(info))
}
onSayHelloEnd(info: object) {
console.log('napiTestDemo ----onSayHelloEnd.', info);
AppStorage.SetOrCreate("textInfoEnd", JSON.stringify(info))
}
}
export default napitest;
let listener: NodeISayHelloListenerImpl = new NodeISayHelloListenerImpl()
```
2. 生成的napitest.cpp给out赋初值
1.2 定义register注册的回调
```
out = "NapiOut";
function onCallbackfunnm(wid: number) {
AppStorage.SetOrCreate("callBackNum", JSON.stringify(wid))
console.info("wid = " + wid)
return "ocCallbackfuncnm";
}
```
3. 在DevEco Studio中增加调用napi方法的测试用例。其中修改index.js文件内容如下
2.注册回调:
2.1 addXXX注册object回调
```
ns.addSayHelloListener(listener);
```
2.2 registerXXX注册回调
```
ns.registerCallbackfunc(onCallbackfunnm);
```
3.调用回调:
3.1 调用sayHello普通函数该函数业务实现会调用注册的object回调
```
ns.sayHello("js1", "native1", napitest.SayType.kInitiative);
```
调用成功后DevEco中HiLog打印传入的参数
```
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello from=js1
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello to=native1
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello sayType=0
```
js层打印回调数据
```
A03d00/JSAPP: napiTestDemo ----onSayHelloStart {"from":"js1","fromId":992,"to":"native1","toId":1014,"content":"hello1","saidTime":"123456789","isEnd":false}
...
A03d00/JSAPP: napiTestDemo ----onSayHelloEnd. {"from":"native","fromId":101,"to":"js","toId":99,"content":"hello","saidTime":"987654321","isEnd":true}
```
3.2 调用sayHi普通函数该函数业务实现会调用register注册的object回调
```
ns.sayHi("js3", "native3", napitest.SayType.kResponse);
```
调用成功后DevEco中HiLog打印传入的参数
```
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi from=js3
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi to=native3
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi sayType=1
```
js层打印回到数据
```
I A03d00/JSAPP: napiTestDemo ----onCallbackfunnm wid = 50
```
4.注销回调:
4.1 removeXXX注销object回调
```
ns.removeSayHelloListener(listener);
```
注销回调后再次调用sayHello方法js层将无法再打印出回调数据
```
ns.sayHello("js2", "native2", napitest.SayType.kInitiative);
```
4.2 unRegisterXXX注销回调
```
ns.unRegisterCallbackfunc(onCallbackfunnm);
```
注销回调后再次调用sayHi方法js层将无法再打印出回调数据
```
ns.sayHi("js4", "native4", napitest.SayType.kResponse);
```
5.调用Promise回调
```
await ns.sayHelloWithResponse("response from", "response to", napitest.SayType.kResponse).then((ret: object) => {
this.promiseRes = JSON.stringify(ret);
console.info("napiTestDemo ----sayHelloWithResponse ret = " + JSON.stringify(ret));
});
```
调用成功后DevEco中HiLog打印传入的参数
```
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHelloWithResponse from=response from
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHelloWithResponse to=response to
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHelloWithResponse sayType=1
```
js层打印promise回调数据
```
I A03d00/JSAPP: napiTestDemo ----sayHelloWithResponse ret = {"result":0,"errMsg":"","response":""}
```
6.调用普通方法funcTest
```
this.returnVal = napitest.funcTest(false);
console.info("napiTestDemo ----funcTest returnVal = " + this.returnVal)
```
调用成功后在js层打印返回值
```
I A03d00/JSAPP: napiTestDemo ----funcTest returnVal = "ret is false"
```
7.调用其他模块entry模块的方法add
```
this.addResult = testEntry.add(2, 3).toString();
console.info("napiTestDemo ----add addResult = " + this.addResult)
```
调用成功后在js层打印返回值
```
I A03d00/JSAPP: napiTestDemo ----add addResult = 5
```
8.Text打印数据说明
```
import router from '@ohos.router';
import napitest from 'libnapitest.so';
export default {
data: {
title: ""
},
onInit(){
this.title = this.$t('strings.world');
},
onclick: function () {
router.push({
url: "pages/index/index.js"
})
},
ontest: function () {
console.log("napitest begin AAAAAAAAAAAAAAAAAA")
let testOut = napitest.func1("NapiIn");
console.info("napitest testOut = " + testOut);
console.log("napitest end AAAAAAAAAAAAAAAAAA")
}
}
```
修改index.html文件内容如下
```
<!--index.hml-->
<div class="container">
<text class="title">
Hello World
</text>
<!-- 添加按钮值为Next并绑定onclick方法-->
<input class="btn" type="button" value="Next" onclick="onclick"></input>
<input class="btn" type="button" value="napitest" onclick="ontest"></input>
</div>
// 调用工具模块napitest中的sayHelloWithResponse后保存promise回调数据
Text('promise回调: promiseResult = ' + this.promiseRes).margin({ top: 10 })
// 调用工具模块napitest中的sayHello方法后保留addXXX注册的回调方法数据
Text('sayHelloStart回调: info = ' + this.textInfoStart).margin({ top: 10 })
Text('sayHelloEnd回调: info = ' + this.textInfoEnd).margin({ top: 10 })
// 调用工具模块napitest中的sayHi方法后保留registerXXX注册的回调方法数据
Text('register注册的回调 wid = ' + this.callBackNum).margin({ top: 10 })
// 调用工具模块napitest中的fucnTest方法后保存返回值
Text('普通方法funcTest返回值 returnVal = ' + this.returnVal).margin({ top: 10 })
// 调用其他模块entry中的add方法后保存返回值
Text('libentry模块: 2 + 3 = ' + this.addResult).margin({ top: 10 })
```
## 使用说明
@ -71,16 +215,68 @@ export default {
2. 连接设备,并点击右上角三角符号编译打包。
1.0.3版本的build-profile.json5文件去掉了"externalNativeOptions"中的abiFilters"字段该字段含义是指定编译的版本默认打包可能会编译x86,arm64,arm32三个版本的.so文件都在hap包里会比较大指定这个就只打arm64和arm32若用户想过滤版本可自行增加该字段
```
"abiFilters": ["armeabi-v7a", "arm64-v8a"]
```
![](../../../figures/DevEco_build.png)
4. 执行成功后设备中会出现安装的APP并进入APP测试页面点击测试按钮DevEco Studio控制台中Log->OpenLog中会出现以下结果
3. 执行成功后设备中会出现安装的APP并进入APP测试页面
点击"注册object回调后SayHello调用回调"按钮APP页面中sayHelloStart回调info和sayHelloEnd回调info会显示出C++传到js层的回调数据DevEco Studio控制台中Log->HiLog中会出现以下结果:
```
01-01 09:05:46.719 3225-3237/com.example.myapplication I A0c0d0/JSApp: app Log: napitest begin AAAAAAAAAAAAAAAAAA
01-01 09:05:46.719 3225-3237/com.example.myapplication I A0c0d0/JSApp: app Log: napitest testOut = NapiOut
01-01 09:05:46.719 3225-3237/com.example.myapplication I A0c0d0/JSApp: app Log: napitest end AAAAAAAAAAAAAAAAAA
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello from=js1
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello to=native1
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello sayType=0
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloStartCallback begin
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloStartCallback end
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloEndCallback begin
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloEndCallback end
```
点击“注销object回调后SayHello调用回调”按钮sayHelloStart回调info和sayHelloEnd回调info会显示出数据为空即该回调已注销C++无法调用回调显示的为应用赋的空值DevEco Studio控制台中Log->HiLog中会出现以下结果:
```
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello from=js2
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello to=native2
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHello sayType=0
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloStartCallback begin
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloStartCallback end
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloEndCallback begin
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI NodeISayHelloListener_onSayHelloEndCallback end
```
点击“Promise 回调”按钮Promise回调的errMsg, result, response会出现C++传到js层的回调数据DevEco Studio控制台中Log->HiLog中会出现以下结果:
```
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHelloWithResponse from=response from
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHelloWithResponse to=response to
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHelloWithResponse sayType=1
```
点击“register回调后SayHi调用回调”按钮register注册的回调会显示出wid = 50, wid值为C++传到js的回调数据DevEco Studio控制台中Log->HiLog中会出现以下结果:
```
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi from=js3
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi to=native3
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi sayType=1
```
点击“unRegister回调后SayHi调用回调”按钮register注册的回调会显示出wid 为空即该回调已注销C++无法调用回调显示的为应用赋的空值DevEco Studio控制台中Log->HiLog中会出现以下结果:
```
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi from=js4
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi to=native4
A03200/MY_TAG com.example.napitestdemo I NAPITEST_LOGI sayHi sayType=1
```
点击”调用funcTest方法“按钮普通方法funcTest返回值显示出 returnVal = ret is false。
点击“调用entry模块的方法”按钮libentry模块2 + 3 = 5。
![](../../../figures/DevEco_run_result.png)
## 相关仓

View File

@ -28,7 +28,7 @@ File->New->Create Project。
![](../../../figures/DevEco_step_newFile.png)
Ability Template选择Empty Ability,单击Next。
Ability Template选择Native C++,单击Next。
![](../../../figures/DevEco_step_firstNext.png)
@ -36,25 +36,37 @@ Ability Template选择Empty Ability,单击Next。
![](../../../figures/DevEco_step_finish.png)
2.安装插件File->Settings->Plugins->Installed->Install Plugin from Disk...选择下载的napi_generator.jar安装成功之后重启IDE。
2.安装插件File->Settings->Plugins->Installed->Install Plugin from Disk...选择下载的napi_generator1.0.3版本及之后的是.zip包之前的是.jar包)安装成功之后重启IDE。
![](../../../figures/DevEco_step_pluginsOk.png)
安装jar包v1.0.3之前
![](../../../figures/DevEco_step_applyPlugins.png)
安装zip包v1.0.3及之后
![](../../../figures/DevEco_step_applyPlugins_zip.png)
3.把待转换的.d.ts文件放在DevEco stdio新建项目的src目录下。若.d.ts文件中声明了basic.d.ts文件将basic.d.ts文件放置在待转换.d.ts文件同一级目录若除此之外还声明其它.d.ts文件将此类文件放置在待转换.d.ts文件同级目录。
![](../../../figures/DevEco_step_napi.png)
4.选择.d.ts文件,点击右键选择 Generate Napi Frame工具弹出Generate Napi Frame弹窗。接口文件文本框填写.d.ts文件路径生成框架路径文本框填写生成框架存放路径编译脚本路径填写生成CMakeList.txt文件输出路径number目的类型此处选择char启用import功能不选择待转换.d.ts文件未引用其它文件点击ok。
4.选择.d.ts文件,点击右键选择 Generate Napi Frame工具弹出Generate Napi Frame弹窗。接口文件文本框填写.d.ts文件路径生成框架路径文本框填写生成框架存放路径编译脚本路径填写生成CMakeList.txt文件输出路径number目的类型此处选择char启用import功能不选择待转换.d.ts文件未引用其它文件配置业务代码按钮可用于配置接口的业务代码,框架根据配置自动粘合工具代码与业务代码;若用户想手动配置业务代码,则不点击配置按钮配置。点击ok。
![](../../../figures/DevEco_step_napiGenerate.png)
![](../../../figures/DevEco_step_napi_ok.png)
5.执行结束后会在对应生成框架路径目录下生成napi框架代码文件。
![](../../../figures/DevEco_step_config_info.png)
![](../../../figures/DevEco_step_show_configInfo.png)
5.执行结束后会在对应生成框架路径目录下生成napi框架代码文件会修改编译脚本路径下的CMakeLists.txt且在此路径下会生成业务代码配置的cfg.json文件其中cfg.json文件内容如下所示
[cfg.json](https://gitee.com/openharmony/napi_generator/blob/master/examples/pluginCase/cfg.json)
## DevEco Studio编译打包说明
NAPI框架代码生成后系统框架开发者进行二次开发后可在DevEco Studio进行编译打包生成对应的库文件供应用开发者调用接口。DevEco Studio编译打包说明的具体操作步骤可以左键单击以下链接了解
[DevEco Studio编译打包说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_IntelliJ_plugin/docs/napi/INSTRUCTION_BUILD_ZH.md)
[DevEco Studio编译打包说明](https://gitee.com/openharmony/napi_generator/blob/master/napi_IntelliJ_plugin/docs/napi/INSTRUCTION_BUILD_ZH.md)