# import nativeæ¨¡å— åœ¨ES6(ECMAScript6.0)模å—设计ä¸ï¼Œç¤¾åŒºä½¿ç”¨importè¯æ³•åŠ è½½å…¶ä»–æ–‡ä»¶å¯¼å‡ºçš„å†…å®¹ï¼ˆECMAè§„èŒƒå®šä¹‰è¯æ³•è§„æ ¼ï¼‰ã€‚ 为支æŒå¼€å‘者便æ·ä½¿ç”¨è¯¥åŠŸèƒ½å¯¼å…¥native模å—(so)导出的内容,ArkTS进行相关适é…ï¼Œå¹¶ç»™å‡ºä»¥ä¸‹å‡ ç§æ”¯æŒå†™æ³•。 ## 直接导入 在native模å—çš„index.d.ts文件ä¸å¯¼å‡ºï¼Œåœ¨æ–‡ä»¶å†…直接导入。 ### å…·å导入 ```ts // libentry.so对应的index.d.ts export const add: (a: number, b: number) => number; ``` ```ts // test.ets import { add } from 'libentry.so' add(2, 3); ``` ### 默认导入 ```ts // libentry.so对应的index.d.ts export const add: (a: number, b: number) => number; ``` ```ts // test.ets import add from 'libentry.so' add.add(2, 3); ``` ### 命å空间导入 ```ts // libentry.so对应的index.d.ts export const add: (a: number, b: number) => number; ``` ```ts // test.ets import * as add from 'libentry.so' add.add(2, 3); ``` ## 间接导入 ### 转为具åå˜é‡å¯¼å‡ºå†å¯¼å…¥ ```ts // test1.ets import hilog from '@ohos.hilog' export { hilog } ``` ```ts // test2.ets import { hilog } from './test1' hilog.info(0x000, 'testTag', '%{public}s', 'test'); ``` ### 转为命å空间导出å†å¯¼å…¥ ```ts // libentry.so对应的index.d.ts export const add: (a: number, b: number) => number; ``` ```ts // test1.ets export * from 'libentry.so' ``` ```ts // test2.ets import { add } from './test1' add(2, 3); ``` **注æ„:** 䏿”¯æŒnative模å—å¯¼å‡ºå’Œå¯¼å…¥åŒæ—¶ä½¿ç”¨å‘½å空间。 **å例:** ```ts // test1.ets export * from 'libentry.so' ``` ```ts // test2.ets import * as add from 'file1' // æ— æ³•èŽ·å–add对象 ``` ## 动æ€å¯¼å…¥ ### 直接导入 ```ts // libentry.so对应的index.d.ts export const add: (a: number, b: number) => number; ``` ```ts // test.ets import('libentry.so').then((ns:ESObject) => { ns.default.add(2, 3); }) ``` ### 间接导入 ```ts // test1.ets import add from 'libentry.so' export { add } // test2.ets import('./test1').then((ns:ESObject) => { ns.add.add(2, 3); }) ``` **注æ„:** 䏿”¯æŒåЍæ€åŠ è½½æ—¶ï¼Œå¯¼å‡ºæ–‡ä»¶ä½¿ç”¨å‘½å空间导出。 **å例:** ```ts // test1.ets export * from 'libentry.so' ``` ```ts // test2.ets import('./test1').then((ns:ESObject) => { // æ— æ³•èŽ·å–ns对象 }) ```