From 2f55f87ea6be08bb2bf9e553eee48f199cabec61 Mon Sep 17 00:00:00 2001 From: wangqiuyun <727176064@qq.com> Date: Tue, 2 Dec 2025 17:16:49 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=20=E6=9B=B4=E6=96=B0=E6=8C=87=E5=AF=BC?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangqiuyun <727176064@qq.com> --- en/react-native-sqlite-storage.md | 82 ++++++++++++++++++++++++--- zh-cn/react-native-sqlite-storage.md | 84 +++++++++++++++++++++++++--- 2 files changed, 148 insertions(+), 18 deletions(-) diff --git a/en/react-native-sqlite-storage.md b/en/react-native-sqlite-storage.md index 73859e53..8395703d 100644 --- a/en/react-native-sqlite-storage.md +++ b/en/react-native-sqlite-storage.md @@ -17,7 +17,15 @@ ## Installation and Usage -Find the matching version information in the release address of a third-party library: [@react-native-oh-tpl/react-native-sqlite-storage Releases](https://github.com/react-native-oh-library/react-native-sqlite-storage/releases).For older versions that are not published to npm, please refer to the [installation guide](/en/tgz-usage-en.md) to install the tgz package. +Please refer to the Releases page of the third-party library for the corresponding version information + +| Third-party Library Version | Release Information | Supported RN Version | +|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| ---------- | +| 6.0.1@deprecated | [@react-native-oh-tpl/react-native-sqlite-storage Releases(deprecated)](https://github.com/react-native-oh-library/react-native-sqlite-storage/releases) | 0.72 | +| 6.0.2 | [@react-native-ohos/react-native-sqlite-storage Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-sqlite-storage/releases) | 0.72 | +| 6.1.0 | [@react-native-ohos/react-native-sqlite-storage Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-sqlite-storage/releases) | 0.77 | + +For older versions that are not published to npm, please refer to the [installation guide](/en/tgz-usage-en.md) to install the tgz package. Go to the project directory and execute the following instruction: @@ -28,13 +36,13 @@ Go to the project directory and execute the following instruction: #### **npm** ```bash -npm install @react-native-oh-tpl/react-native-sqlite-storage +npm install @react-native-ohos/react-native-sqlite-storage ``` #### **yarn** ```bash -yarn add @react-native-oh-tpl/react-native-sqlite-storage +yarn add @react-native-ohos/react-native-sqlite-storage ``` The following code shows the basic use scenario of the repository: @@ -530,11 +538,15 @@ export default SQLiteDemo; ## Use Codegen +Version >= @react-native-ohos/react-native-sqlite-storage@6.0.2, compatible with codegen-lib for generating bridge code. + this repository has been adapted to `Codegen`, generate the bridge code of the third-party library by using the `Codegen`. For details, see [Codegen Usage Guide](/en/codegen.md). ## Link -Currently, HarmonyOS does not support AutoLink. Therefore, you need to manually configure the linking. +Version >= @react-native-ohos/react-native-sqlite-storage@6.0.2 now supports Autolink without requiring manual configuration, currently only supports 72 frameworks. Autolink Framework Guide Documentation: https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md + +This step provides guidance for manually configuring native dependencies. Open the `harmony` directory of the HarmonyOS project in DevEco Studio. @@ -563,7 +575,7 @@ Open `entry/oh-package.json5` file and add the following dependencies: ```json "dependencies": { "@rnoh/react-native-openharmony": "file:../react_native_openharmony", - "@react-native-oh-tpl/react-native-sqlite-storage": "file:../../node_modules/@react-native-oh-tpl/react-native-sqlite-storage/platforms/harmony/sqlite_storage.har" + "@react-native-ohos/react-native-sqlite-storage": "file:../../node_modules/@react-native-ohos/react-native-sqlite-storage/harmony/sqlite_storage.har" } ``` @@ -580,14 +592,62 @@ Method 2: Directly link to the source code. > [!TIP] For details, see [Directly Linking Source Code](/en/link-source-code.md). +### 3. Configure CMakeLists and import SQLitePluginPackage + +> V6.0.2 requires configuring CMakeLists and importing SQLitePluginPackage. + +Open the `entry/src/main/cpp/CMakeLists.txt` file and add the following code: + +```diff +... + +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_END: manual_package_linking_1 +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) + +# RNOH_END: manual_package_linking_1 -### 3. Introducing SQLitePluginPackage to ArkTS +add_library(rnoh_app SHARED + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) + +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) ++ target_link_libraries(rnoh_app PUBLIC rnoh_sqlite_storage) +# RNOH_BEGIN: manual_package_linking_2 +``` + +Open the `entry/src/main/cpp/PackageProvider.cpp` file and add the following code: + +```diff +#include "RNOH/PackageProvider.h" ++ #include "SQLitePluginPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { ++ std::make_shared(ctx) +} +``` + +### 4. Introducing SQLitePluginPackage to ArkTS Open the `entry/src/main/ets/RNPackagesFactory.ts` file and add the following code: ```diff ... -+ import {SQLitePluginPackage} from '@react-native-oh-tpl/react-native-sqlite-storage/ts'; ++ import {SQLitePluginPackage} from '@react-native-ohos/react-native-sqlite-storage/ts'; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ @@ -597,7 +657,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 4. Running +### 5. Running Click the `sync` button in the upper right corner. @@ -614,7 +674,11 @@ Then build and run the code. To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone. -Check the release version information in the release address of the third-party library:[@react-native-oh-tpl/react-native-sqlite-storage Releases](https://github.com/react-native-oh-library/react-native-sqlite-storage/releases) +The following combinations have been verified: + +1. RNOH: 0.72.96; SDK: HarmonyOS 5.1.0.150 (API Version 12); IDE: DevEco Studio 5.1.1.830; ROM: 5.1.0.150; +2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71; +3. RNOH: 0.77.18; SDK: HarmonyOS 5.0.0.71(API Version 12 Release) ;IDE:DevEco Studio:5.1.1.830; ROM: HarmonyOS 5.1.0.150; ## Static Methods diff --git a/zh-cn/react-native-sqlite-storage.md b/zh-cn/react-native-sqlite-storage.md index 305b2232..865893d1 100644 --- a/zh-cn/react-native-sqlite-storage.md +++ b/zh-cn/react-native-sqlite-storage.md @@ -17,7 +17,15 @@ ## 安装与使用 -请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/react-native-sqlite-storage Releases](https://github.com/react-native-oh-library/react-native-sqlite-storage/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 +请到三方库的 Releases 发布地址查看配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 6.0.1@deprecated | [@react-native-oh-tpl/react-native-sqlite-storage Releases(deprecated)](https://github.com/react-native-oh-library/react-native-sqlite-storage/releases) | 0.72 | +| 6.0.2 | [@react-native-ohos/react-native-sqlite-storage Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-sqlite-storage/releases) | 0.72 | +| 6.1.0 | [@react-native-ohos/react-native-sqlite-storage Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-sqlite-storage/releases) | 0.77 | + +对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 进入到工程目录并输入以下命令: @@ -26,13 +34,13 @@ #### **npm** ```bash -npm install @react-native-oh-tpl/react-native-sqlite-storage +npm install @react-native-ohos/react-native-sqlite-storage ``` #### **yarn** ```bash -yarn add @react-native-oh-tpl/react-native-sqlite-storage +yarn add @react-native-ohos/react-native-sqlite-storage ``` 下面的代码展示了这个库的基本使用场景: @@ -528,11 +536,16 @@ export default SQLiteDemo; ## 使用 Codegen +Version >= @react-native-ohos/react-native-sqlite-storage@6.0.2,已适配codegen-lib生成桥接代码。 + 本库已经适配了 `Codegen` ,在使用前需要主动执行生成三方库桥接代码,详细请参考[ Codegen 使用文档](/zh-cn/codegen.md)。 ## Link -目前HarmonyOS暂不支持 AutoLink,所以 Link 步骤需要手动配置。 +Version >= @react-native-ohos/react-native-sqlite-storage@6.0.2,已支持 Autolink,无需手动配置,目前只支持72框架。 +Autolink框架指导文档:https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md + +此步骤为手动配置原生依赖项的指导。 首先需要使用 DevEco Studio 打开项目里的HarmonyOS工程 `harmony` @@ -563,7 +576,7 @@ export default SQLiteDemo; ```json "dependencies": { "@rnoh/react-native-openharmony": "file:../react_native_openharmony", - "@react-native-oh-tpl/react-native-sqlite-storage": "file:../../node_modules/@react-native-oh-tpl/react-native-sqlite-storage/platforms/harmony/sqlite_storage.har" + "@react-native-ohos/react-native-sqlite-storage": "file:../../node_modules/@react-native-ohos/react-native-sqlite-storage/harmony/sqlite_storage.har" } ``` @@ -581,13 +594,62 @@ ohpm install > [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) -### 3.在 ArkTs 侧引入 SQLitePluginPackage +### 3. 配置 CMakeLists 和引入 SQLitePluginPackage + +> V6.0.2 需要配置 CMakeLists 和引入 SQLitePluginPackage. + +打开 `entry/src/main/cpp/CMakeLists.txt`,添加: + +```diff +... + +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_END: manual_package_linking_1 +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) + +# RNOH_END: manual_package_linking_1 + +add_library(rnoh_app SHARED + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) + +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) ++ target_link_libraries(rnoh_app PUBLIC rnoh_sqlite_storage) +# RNOH_BEGIN: manual_package_linking_2 +``` + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" ++ #include "SQLitePluginPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { ++ std::make_shared(ctx) +} +``` + +### 4. 在 ArkTs 侧引入 SQLitePluginPackage 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: ```diff ... -+ import {SQLitePluginPackage} from '@react-native-oh-tpl/react-native-sqlite-storage/ts'; ++ import {SQLitePluginPackage} from '@react-native-ohos/react-native-sqlite-storage/ts'; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ @@ -597,7 +659,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 4.运行 +### 5. 运行 点击右上角的 `sync` 按钮 @@ -614,7 +676,11 @@ ohpm install 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 -请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-sqlite-storage Releases](https://github.com/react-native-oh-library/react-native-sqlite-storage/releases) +在以下版本验证通过: + +1. RNOH: 0.72.96; SDK: HarmonyOS 5.1.0.150 (API Version 12); IDE: DevEco Studio 5.1.1.830; ROM: 5.1.0.150; +2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71; +3. RNOH: 0.77.18; SDK: HarmonyOS 5.0.0.71(API Version 12 Release) ;IDE:DevEco Studio:5.1.1.830; ROM: HarmonyOS 5.1.0.150; ## 静态方法 -- Gitee