From 7e04ff8f1e38aff69d01bae86515c577a34e4bcd Mon Sep 17 00:00:00 2001 From: wsl <1105069392@qq.com> Date: Tue, 30 Sep 2025 16:43:09 +0800 Subject: [PATCH] =?UTF-8?q?BptaUseResources=E5=B7=A5=E7=A8=8B=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wsl <1105069392@qq.com> --- BptaUseResources/README.md | 30 +++++--- .../entry/src/main/cpp/CMakeLists.txt | 15 ++++ .../main/{ets/pages/music => cpp}/OpenSL.cpp | 14 ++++ .../entry/src/main/cpp/napi_init.cpp | 68 +++++++++++++++++++ .../src/main/cpp/types/libentry/index.d.ts | 1 + .../main/cpp/types/libentry/oh-package.json5 | 6 ++ BptaUseResources/entry/src/main/module.json5 | 4 +- .../main/resources/base/element/string.json | 2 +- 8 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 BptaUseResources/entry/src/main/cpp/CMakeLists.txt rename BptaUseResources/entry/src/main/{ets/pages/music => cpp}/OpenSL.cpp (60%) create mode 100644 BptaUseResources/entry/src/main/cpp/napi_init.cpp create mode 100644 BptaUseResources/entry/src/main/cpp/types/libentry/index.d.ts create mode 100644 BptaUseResources/entry/src/main/cpp/types/libentry/oh-package.json5 diff --git a/BptaUseResources/README.md b/BptaUseResources/README.md index 974f20ce..6d391524 100644 --- a/BptaUseResources/README.md +++ b/BptaUseResources/README.md @@ -4,17 +4,31 @@ 无长时任务的应用退到后台时,不允许进行蓝牙扫描。 +### 使用说明 +不涉及 + ### 工程结构&模块类型 ``` -├──entry/src/main/ets/ -│ ├──entryability -│ │ └──EntryAbility.ets // 配置类 -│ └──pages -│ └──Index.ets // 程序入口 -│ └──Https.ets // HTTP数据请求 -│ └──Bluetooth.ets // 合理使用蓝牙资源 -└──entry/src/main/resource // 应用静态资源目录 +├──entry/src/main +│ ├──ets +│ │ ├──entryability +│ │ │ └──EntryAbility.ets // 配置类 +│ │ ├──entrybackupability +│ │ │ └──EntryBackupAbility.ets // 应用数据备份恢复类 +│ │ └──pages +│ │ ├──Index.ets // 程序入口 +│ │ ├──Gps.ets // gps示例 +│ │ ├──Sensor.ets // 传感器示例 +│ │ ├──Socket.ets // socket示例 +│ │ ├──WebSocket.ets // WebSocket示例 +│ │ ├──Https.ets // HTTP数据请求 +│ │ └──Bluetooth.ets // 合理使用蓝牙资源 +│ └──cpp +│ ├──CMakeLists.txt +│ ├──napi_init.cpp // 合理使用蓝牙资源 +│ └──OpenSL.cpp // 初始化代码 +└──entry/src/main/resource // 应用静态资源目录 ``` diff --git a/BptaUseResources/entry/src/main/cpp/CMakeLists.txt b/BptaUseResources/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 00000000..1acd3ec1 --- /dev/null +++ b/BptaUseResources/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(CppCrash) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/BptaUseResources/entry/src/main/ets/pages/music/OpenSL.cpp b/BptaUseResources/entry/src/main/cpp/OpenSL.cpp similarity index 60% rename from BptaUseResources/entry/src/main/ets/pages/music/OpenSL.cpp rename to BptaUseResources/entry/src/main/cpp/OpenSL.cpp index 23a867c9..000428eb 100644 --- a/BptaUseResources/entry/src/main/ets/pages/music/OpenSL.cpp +++ b/BptaUseResources/entry/src/main/cpp/OpenSL.cpp @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ /** * 最佳实践:合理使用音频资源 * 场景三:播音场景(OpenSL ES) diff --git a/BptaUseResources/entry/src/main/cpp/napi_init.cpp b/BptaUseResources/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 00000000..d0e1aafc --- /dev/null +++ b/BptaUseResources/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args , nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; + +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/BptaUseResources/entry/src/main/cpp/types/libentry/index.d.ts b/BptaUseResources/entry/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 00000000..e44f3615 --- /dev/null +++ b/BptaUseResources/entry/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1 @@ +export const add: (a: number, b: number) => number; \ No newline at end of file diff --git a/BptaUseResources/entry/src/main/cpp/types/libentry/oh-package.json5 b/BptaUseResources/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 00000000..17f2fec2 --- /dev/null +++ b/BptaUseResources/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/BptaUseResources/entry/src/main/module.json5 b/BptaUseResources/entry/src/main/module.json5 index 34457eca..2695312b 100644 --- a/BptaUseResources/entry/src/main/module.json5 +++ b/BptaUseResources/entry/src/main/module.json5 @@ -5,9 +5,7 @@ "description": "$string:module_desc", "mainElement": "EntryAbility", "deviceTypes": [ - "phone", - "tablet", - "2in1" + "phone" ], "deliveryWithInstall": true, "installationFree": false, diff --git a/BptaUseResources/entry/src/main/resources/base/element/string.json b/BptaUseResources/entry/src/main/resources/base/element/string.json index f9459551..6c331839 100644 --- a/BptaUseResources/entry/src/main/resources/base/element/string.json +++ b/BptaUseResources/entry/src/main/resources/base/element/string.json @@ -10,7 +10,7 @@ }, { "name": "EntryAbility_label", - "value": "label" + "value": "BptaUseResources" } ] } \ No newline at end of file -- Gitee