1# DevEco Studio编译打包说明 2 3## 简介 4 本文主要介绍使用IntelliJ插件将ts接口文件名格式如下ohos.A.B.C.d.ts文件转换后如何在DevEco Studio进行编译打包。 5 6## 准备 7 81. 待转换的@ohos.napitest.d.ts文件如下: 9 10``` 11import {AsyncCallback} from './basic'; 12 13declare namespace napitest { 14 function fun1(v1: string): string; 15} 16 17export default napitest; 18``` 19 202. 生成的napitest.cpp给out赋初值: 21 22``` 23out = "NapiOut"; 24``` 25 263. 在DevEco Studio中增加调用napi方法的测试用例。其中修改index.js文件内容如下: 27 28 29``` 30import router from '@ohos.router'; 31import napitest from 'libnapitest.so'; 32export default { 33 data: { 34 title: "" 35 }, 36 onInit(){ 37 this.title = this.$t('strings.world'); 38 }, 39 onclick: function () { 40 router.push({ 41 url: "pages/index/index.js" 42 }) 43 }, 44 ontest: function () { 45 console.log("napitest begin AAAAAAAAAAAAAAAAAA") 46 let testOut = napitest.func1("NapiIn"); 47 console.info("napitest testOut = " + testOut); 48 console.log("napitest end AAAAAAAAAAAAAAAAAA") 49 } 50} 51``` 52 修改index.html文件内容如下: 53 54``` 55 <!--index.hml--> 56 <div class="container"> 57 <text class="title"> 58 Hello World 59 </text> 60 <!-- 添加按钮,值为Next,并绑定onclick方法--> 61 <input class="btn" type="button" value="Next" onclick="onclick"></input> 62 <input class="btn" type="button" value="napitest" onclick="ontest"></input> 63 </div> 64``` 65 66## 使用说明 67 681. 在File->Project Structure->Project->Signing Configs自动签名,点击OK即可。 69 70  71 722. 连接设备,并点击右上角三角符号编译打包。 73 74  75 764. 执行成功后,设备中会出现安装的APP并进入APP测试页面,点击测试按钮DevEco Studio控制台中Log->OpenLog中会出现以下结果: 77 78 ``` 79 01-01 09:05:46.719 3225-3237/com.example.myapplication I A0c0d0/JSApp: app Log: napitest begin AAAAAAAAAAAAAAAAAA 80 01-01 09:05:46.719 3225-3237/com.example.myapplication I A0c0d0/JSApp: app Log: napitest testOut = NapiOut 81 01-01 09:05:46.719 3225-3237/com.example.myapplication I A0c0d0/JSApp: app Log: napitest end AAAAAAAAAAAAAAAAAA 82 ``` 83 84  85 86## 相关仓 87 88暂无 89