首页
开源
资讯
活动
开源许可证
软件工程云服务
软件代码质量检测云服务
持续集成与部署云服务
社区个性化内容推荐服务
贡献审阅人推荐服务
群体化学习服务
重睛鸟代码扫描工具
登录
注册
代码拉取完成,页面将自动刷新
当前仓库属于暂停状态,部分功能使用受限,详情请查阅
仓库状态说明
Watch
35
Star
81
Fork
22
ArkUI-X
/
samples
暂停
Fork 仓库
加载中
取消
确认
代码
Issues
29
Pull Requests
0
Wiki
0
统计
更新失败,请稍后重试!
Issues
/
详情
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
taskPool方法中调用napi接口报错
待确认
#I8TYBG
缺陷
it21sj
创建于
2024-01-05 17:01
### 该问题是怎么引起的? 主要适用场景用于在lib module中处理耗时任务,这个时候就需要用到taskpool方法, 如果在function中处理耗时,不涉及napi是没有问题的; 如果在function中需要调用napi的方法,那么就会报错 is not called,找不到napi的方法,napi方法不在taskpool中调用是没有问题的; ### 重现步骤 1. 打开simple中的native项目 2. 编译项目,使得项目可以正常运行 3. 修改index.ets文件内容,文件内容在文末;index文件:Native/entry/src/main/ets/pages/Index.ets 4. 菜单:build→build haps/apps→build apps 5. 打开as导入.akui-x中的android项目 6. 安装到Android手机上运行,即可复现问题 ### 报错信息 napi接口调用报错: is not called index.ets源码: ``` /* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import testNapi from 'libentry.so'; import taskpool from '@ohos.taskpool'; @Concurrent async function normalTask(a: number, b: number): Promise<number> { return a + b } @Concurrent async function napiTest(a: number, b: number): Promise<number> { console.log("taskPool Result 2"); const addRes = testNapi.add(a, b) console.log("taskPool Result s" + addRes); return addRes } @Entry @Component struct Index { @State message: string = 'Test native api: 2 + 3 = ?' @State message2: string = 'Click me' @State taskNormal: string = 'taskPool Result normal : 5 + 6 = ?' @State taskNapi: string = 'taskPool Result : 5 + 6 = ?' build() { Row() { Column() { Text(this.message) .fontSize(20) .fontWeight(FontWeight.Bold) .alignSelf(ItemAlign.Start) .margin({ left: 5 }) .onClick(() => { this.message = "Test native api: 2 + 3 = " + testNapi.add(2, 3); console.log("Test NAPI 2 + 3 = " + testNapi.add(2, 3)); }) Text(this.message2) .fontSize(20) .alignSelf(ItemAlign.Start) .margin({ top: 20, left: 5 }) .fontWeight(FontWeight.Bold) .onClick(() => { this.message2 = testNapi.nativeCallArkTS((a: string) => { return a + " world!"; }); console.log(this.message2); }) Text(this.taskNormal) .fontSize(20) .alignSelf(ItemAlign.Start) .margin({ top: 20, left: 5 }) .fontWeight(FontWeight.Bold) .onClick(async () => { const result = await taskpool.execute(normalTask, 5, 6) as number this.taskNormal = 'taskPool Result normal : 5 + 6 = ' + result console.log(this.taskNormal); }) Text(this.taskNapi) .fontSize(20) .alignSelf(ItemAlign.Start) .margin({ top: 20, left: 5 }) .fontWeight(FontWeight.Bold) .onClick(async () => { console.log("taskPool Result 1"); taskpool.execute(napiTest, 5, 6).then((result: number) => { console.log("taskPool Result 3"); this.taskNapi = 'taskPool Result : 5 + 6 = ' + result console.log(this.taskNapi); }).catch((reason: Error) => { console.log("taskPool Result exception : " + reason.message); }) }) } .width('100%') } .height('100%') } } ```
### 该问题是怎么引起的? 主要适用场景用于在lib module中处理耗时任务,这个时候就需要用到taskpool方法, 如果在function中处理耗时,不涉及napi是没有问题的; 如果在function中需要调用napi的方法,那么就会报错 is not called,找不到napi的方法,napi方法不在taskpool中调用是没有问题的; ### 重现步骤 1. 打开simple中的native项目 2. 编译项目,使得项目可以正常运行 3. 修改index.ets文件内容,文件内容在文末;index文件:Native/entry/src/main/ets/pages/Index.ets 4. 菜单:build→build haps/apps→build apps 5. 打开as导入.akui-x中的android项目 6. 安装到Android手机上运行,即可复现问题 ### 报错信息 napi接口调用报错: is not called index.ets源码: ``` /* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import testNapi from 'libentry.so'; import taskpool from '@ohos.taskpool'; @Concurrent async function normalTask(a: number, b: number): Promise<number> { return a + b } @Concurrent async function napiTest(a: number, b: number): Promise<number> { console.log("taskPool Result 2"); const addRes = testNapi.add(a, b) console.log("taskPool Result s" + addRes); return addRes } @Entry @Component struct Index { @State message: string = 'Test native api: 2 + 3 = ?' @State message2: string = 'Click me' @State taskNormal: string = 'taskPool Result normal : 5 + 6 = ?' @State taskNapi: string = 'taskPool Result : 5 + 6 = ?' build() { Row() { Column() { Text(this.message) .fontSize(20) .fontWeight(FontWeight.Bold) .alignSelf(ItemAlign.Start) .margin({ left: 5 }) .onClick(() => { this.message = "Test native api: 2 + 3 = " + testNapi.add(2, 3); console.log("Test NAPI 2 + 3 = " + testNapi.add(2, 3)); }) Text(this.message2) .fontSize(20) .alignSelf(ItemAlign.Start) .margin({ top: 20, left: 5 }) .fontWeight(FontWeight.Bold) .onClick(() => { this.message2 = testNapi.nativeCallArkTS((a: string) => { return a + " world!"; }); console.log(this.message2); }) Text(this.taskNormal) .fontSize(20) .alignSelf(ItemAlign.Start) .margin({ top: 20, left: 5 }) .fontWeight(FontWeight.Bold) .onClick(async () => { const result = await taskpool.execute(normalTask, 5, 6) as number this.taskNormal = 'taskPool Result normal : 5 + 6 = ' + result console.log(this.taskNormal); }) Text(this.taskNapi) .fontSize(20) .alignSelf(ItemAlign.Start) .margin({ top: 20, left: 5 }) .fontWeight(FontWeight.Bold) .onClick(async () => { console.log("taskPool Result 1"); taskpool.execute(napiTest, 5, 6).then((result: number) => { console.log("taskPool Result 3"); this.taskNapi = 'taskPool Result : 5 + 6 = ' + result console.log(this.taskNapi); }).catch((reason: Error) => { console.log("taskPool Result exception : " + reason.message); }) }) } .width('100%') } .height('100%') } } ```
评论 (
0
)
it21sj
创建了
缺陷
登录
后才可以发表评论
状态
待确认
待确认
已确认
修复中
已修复
已验收
已拒绝
负责人
未设置
标签
未设置
项目
未立项任务
未立项任务
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (6)
标签 (5)
master
ArkUI-X-5.0.1-Release
ArkUI-X-2.0.0-Beta1
ArkUI-X-1.1.6-Release
ArkUI-X-1.0.0-Release
ArkUI-X-1.0.0-Canary1
ArkUI-X-v5.0.1-Release
ArkUI-X-v2.0.0-Beta1
ArkUI-X-v1.1.6-Release
ArkUI-X-v1.0.0-Release
ArkUI-X-v1.0.0-Canary1
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(1)