• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Native API Usage
2
3## Is there a native API that provides functions similar to Canvas?
4
5Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
6
7Yes. The native API **Drawing** provides similar functions. It can be used for 2D drawing.
8
9## When a native HAP is running, the error message "Obj is not a valid object" is displayed for the imported namespace. What should I do?
10
11Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
12
13Check the **abiFilters** parameter value in the **build-profile.json5** file in the root directory of the module (not the root directory of the project). If the device is 32-bit, the value must be **armeabi-v7a**. If the device is 64-bit, the value must be **arm64-v8a**.
14
15## What should I do when the error message "install parse profile prop check error" is displayed during the running of a native HAP?
16
17Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9
18
19Check the **abiFilters** parameter value in the **build-profile.json5** file in the root directory of the module (not the root directory of the project). If the device is 32-bit, the value must be **armeabi-v7a**. If the device is 64-bit, the value must be **arm64-v8a**.
20
21## What should I do when the error message "undefined symbol: OH_LOG_Print" is displayed during log printing by **OH_LOG_Print**?
22
23Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9
24
25Modify the **CMakeLists.txt** file by adding **libhilog_ndk.z.so** to the end of **target_link_libraries**.
26
27## How do I obtain the value of version in the package.json file of a module?
28
29Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
30
311. In the script file **hvigorfile.js** of Hvigor, use **subModule.getPackageJsonPath** to obtain the location of the **package.json** file in the module.
32
332. Use Node.js to read the **version** field in the **package.json** file and write the value to the **buildOption.cppFlags** field in the **build-profile.json5** file.
34
35Example
36
37
38```
39// Module-level hvigorfile.js
40const subModule = require('@ohos/hvigor')(__filename)
41
42const fs = require("fs-extra")
43const path = require("path")
44
45const packageJsonPath = subModule.getPackageJsonPath()
46const buildProfilePath = path.resolve(packageJsonPath, '../build-profile.json5')
47const packageJsonData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
48let buildProfileData = fs.readFileSync(buildProfilePath, 'utf8')
49buildProfileData = buildProfileData.replace(/\"cppFlags\"\:(.*)\,/, `"cppFlags": "-D NWEBEX_VERSION=${packageJsonData.version}",`)
50fs.writeFileSync(buildProfilePath, buildProfileData, 'utf8')
51
52const ohosPlugin = require('@ohos/hvigor-ohos-plugin').hapTasks(subModule) // The plug-in executes the C++ build task and reads the build-profile.json5 file.
53
54module.exports = {
55  ohos: ohosPlugin
56}
57```
58
59
60```
61// Read the hello.cpp file.
62#define _NWEBEX_VERSION(v) #v
63#define _NWEBEX_VER2STR(v) _NWEBEX_VERSION(v)
64
65static napi_value Add(napi_env env, napi_callback_info info)
66{
67
68    napi_value fixed_version_value = nullptr;
69    napi_create_string_utf8(env, _NWEBEX_VER2STR(NWEBEX_VERSION), NAPI_AUTO_LENGTH, &fixed_version_value);
70
71    return fixed_version_value;
72}
73```
74
75## How do I traverse files in rawfile?
76
77Applicable to: OpenHarmony SDK 3.2 or later, stage model of API version 9
78
79Use the native API **OH_ResourceManager_OpenRawDir()** to obtain the root directory of **rawfile** and traverse the root directory.
80