目录

Compilation and Building FAQs

What Should I Do If the Memory Usage Is Too High During Compilation?

Symptom

During compilation and build, memory or CPU usage is too high, resulting in issues such as slow response in DevEco Studio.

Solution

What Should I Do If the Error Message "Cannot read properties of undefined(reading 'XXX')" Is Displayed During Build?

Rectify the fault based on the value of XXX. If the fault persists, refer to the final solution.

What Should I Do If the Error Message "Duplicated files found in module xxx. This may cause unexpected errors at runtime" Is Displayed During Build?

Symptom

During the compilation and build process, an error occurs: "Duplicated files found in module xxx. This may cause unexpected errors at runtime".

The error occurs when there are different versions of an .so file with the same name. For example, if you copy the .so file from the har module's product to the libs directory of the entry module, then there is a libhar.so file in both the har module and the entry module. In this case, if you configure the entry module to depend on the har module, the build of the entry module will result in an error.

Solution

Use configurations such as select, pickFirsts, and pickLasts to choose the .so files to be used. select provides precise selection capabilities for native products, with a higher priority than excludes, pickFirsts, and other configuration items. pickFirsts and pickLasts pack the .so file with the highest priority. The priority order refers to the order of dependency collection, and the later it is collected, the higher the priority.

For details, see Configuring for C++ Builds.

Based on the preceding example, you can add a select configuration in the entry module's build-profile.json5 file to choose the .so file from the har module, set package to the "har", and include to "libhar.so".

What Should I Do If the Error Message "input module releaseType is different" Is Displayed During Build?

Symptom

When an App Pack is packaged, the message "input module releaseType is different" is displayed.

Solution

According to the module names indicated in the error message, check whether the apiReleaseType fields are consistent between the modules.

The apiReleaseType field is automatically generated by the compilation and build tool and is saved in the module.json file of the HAP/HSP. As shown in the figure below, first confirm whether this field is consistent between the modules. If there is an inconsistency, you need to repackage each module of the app with the same version of the SDK, and then package the App Pack.

What Should I Do If the Error Message "debug is different" Is Displayed During Build?

Symptom

When an App Pack is packaged, the message "debug is different" is displayed.

Solution

Based on the module names indicated in the error message, check whether the debug fields are consistent between modules, especially between local modules and externally referenced modules.

1. The debug field is automatically generated by the compilation and build tool and saved in the module.json file of the HAP/HSP, as shown in the figure below. First, confirm whether the fields are consistent across all modules.

2. Set Build Mode, based on which the compilation and build tool generates the debug flag.

What Should I Do If the Error Message "proxy data is duplicated" Is Displayed During Build?

Symptom

When an App Pack is packaged, the message "uri datashareproxy://bundleName/** in proxy data is duplicated" is displayed.

Solution

The proxyData field lists the data proxies provided by the module and is only allowed to be configured in entry and feature modules. The URIs configured in different proxyData configurations must not be duplicated. In light of this, if the preceding issue occurs, check whether the proxyData configurations with the same URI is configured between modules.

What Should I Do If the Error Message "Init keystore failed: parseAlgParameters failed: ObjectIdentifier()" Is Displayed During Compilation?

Symptom

During compilation and build, an error occurs: "Init keystore failed: parseAlgParameters failed: ObjectIdentifier()".

hap-sign-tool: error: ACCESS_ERROR, code: 109. Details:   Init keystore failed: parseAlgParameters failed: ObjectIdentifier() -- data isn't an object ID (tag = 48)   Detail: Please check the message from tools

Analysis

Using a higher version of JDK to generate a key pair (.p12), and then using a lower version of JDK to execute the signing command, can lead to incompatibility, causing the .p12 file to fail to parse, and the signing to fail.

Scenarios

  1. When DevEco Studio generates a key pair, it uses the pre-installed JDK by default. If a lower-version JDK is used for signing locally, an error will occur.
  2. If a key pair is generated locally using a higher-version JDK, and signing is performed via DevEco Studio, an error will occur because the pre-installed JDK within DevEco Studio has a lower version than the JDK used locally.

Solution

Check the JDK version currently in use and the version used to generate the key pair, and use a JDK version that matches for executing the signing command.

What Should I Do If the Error Message "generate SignerBlock failed" Is Displayed During Compilation?

Symptom

During compilation and build, an error occurs: message: generate SignerBlock failed.

hap-sign-tool: error: {errorcode:0,message:generate SignerBlock failed}

Analysis

The public and private key pair used for signing does not match. In this case, if you sign with the private key, verification with the public key will fail. Ensure that the private key (keyalias) and public key (appCertPath) are used in pairs.

Scenarios

  1. When the signing material is generated locally, the correct CSR (.csr file) corresponding to keyalias is not exported. As a result, the public key does not match the private key corresponding to keyalias when the certificate is generated.
  2. The keyalias or appCertPath file is incorrect.

Solution

Select the correct, paired keyalias and appCertPath files.

What Should I Do If the Error Message "java.io.IOException: DerValue.getOID, not an OID 49" Is Displayed During Compilation?

Symptom

During the compilation and build process, the error message "java.io.IOException: DerValue.getOID, not an OID 49" is displayed.

hap-sign-tool: error: ACCESS_ERROR, code: 109. Details: java.io.IOException: DerValue.getOID, not an OID 49 Detail: Please check the message from tools

Possible Cause

The certificate file fails to parse, and the certificate's OID could not be found.

Scenarios

  1. The certificate has been tampered with.
  2. The appCertPath parameter has a non-certificate file passed in.

Solution

Make sure the certificate is correct.

What Should I Do If the Error Message "JS heap out of memory" Is Displayed During Compilation?

Symptom

The error message "JS heap out of memory" is displayed during compilation and build.

Solution

The memory for running Hvigor is insufficient. When Hvigor of version 3.1.0 or later is used, modify the maximum memory for running Hvigor. Do as follows:

Select Enable the Daemon for tasks.

Set the value of maxOldSpaceSize in hvigor-config.json5 to a larger value (for example, 8192) based on the project size.

"nodeOptions": {
  "maxOldSpaceSize": 8192
}

What Should I Do If the Error Message "JS heap out of memory" Is Displayed During Compilation in Linux?

Symptom

In a Linux environment, the system has 64 GB of memory. The hvigorw script is configured with --max-old-space-size=40960. During the compilation and build process, an error "JS heap out of memory" occurs even though the actual memory usage has not reached the configured limit (for example, only around 20 GB is used).

FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20200512.172528.47517.24.011.json
Node.js report completed
1: 0xa295e0 node::Abort() [node]
2: 0x9782df node::FatalError(char const*, char const*) [node]
3: 0xb99c2e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xb99fa7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xd3a3b5 [node]
6: 0xd74f27 [node]
7: 0xd84707 v8::internal::MarkCompactCollector::CollectGarbage() [node]
8: 0xd481b9 v8::internal::Heap::MarkCompact() [node]
9: 0xd48f0b v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
10: 0xd499a5 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
11: 0xd4aebf v8::internal::Heap::HandleGCRequest() [node]
12: 0xcf5f97 v8::internal::StackGuard::HandleInterrupts() [node]
13: 0x104b803 v8::internal::Runtime_StackGuard(int, unsigned long*, v8::internal::Isolate*) [node]
14: 0x13a5a99 [node]
Aborted (core dumped)

Possible Causes

As a parameter related to the kernel's virtual memory subsystem, vm.max_map_count controls the maximum number of memory mapping areas that a process can have. It is commonly used to limit the number of files a process can open, especially in cases where a large number of memory-mapped files are used.

On Linux, the default value of vm.max_map_count is usually a relatively small number, such as 65530. However, for some apps that require a large number of memory mappings or for specific use cases, you may need to increase the value of this parameter to allow for more memory mapping areas.

Solution

Change the value of vm.max_map_count.

What Should I Do If the Error Message "Cannot find module XXX or its corresponding type declarations" Is Displayed During Compilation?

What Should I Do If the Error Message "Module 'xxx' has no exported member 'yyy'" Is Displayed During Compilation?

Symptom

The stage model project fails to be compiled and built. The error message "Module 'xxx' has no exported member 'yyy'" is displayed, where the yyy symbol is exported from the x.js file using export * from 'x.js'.

Solution

During compilation and build of the stage model project, the syntax of the .js file is not checked. Therefore, when using export * from 'x.js' to export symbols from an x.js file, "Module 'xxx' has no exported member 'yyy'" is reported where the symbol is referenced.

If a similar problem occurs, perform the following to troubleshoot:

What Should I Do If the Error Message "Could not load ${file1} (imported by ${file2}): Maximum call stack size exceeded" Is Displayed During Compilation?

Symptom

The stage model project fails to be compiled and built, and the message "ERROR: Could not load ${file1} (imported by ${file2}): Maximum call stack size exceeded" is displayed.

Solution

This problem occurs because file1 is the code outside the current project.

Create a Static Library module, migrate the code outside the project to the Static Library module, and reference HAR using HAP to implement cross-module reference.

What Should I Do If the Error Message "Failed to get a resolved OhmUrl by filepath xx" Is Displayed During Compilation?

What Should I Do If the Error Message "Property xxx does not exist on type 'typeof BuildProfile'." Is Displayed During Compilation?

Symptom 1

The user-defined parameter BuildProfile is used. No exception occurs in the compilation phase, but the compilation fails, with the message "Property xxx does not exist on type 'typeof BuildProfile'."

Solution

Check whether the key values of user-defined parameters configured in targets > buildProfileFields in build-profile.json5 of the current module are the same. If they are different, change them to the same.

The following is an example of incorrect configuration that causes the compilation error:

"targets": [
  {
    "name": "default",
    "config": {
      "buildOption": {
        "arkOptions": {
          "buildProfileFields": {
            "targetName": "default"
          }
        }
      }
    }
  },
  {
    "name": "default1",
    "config": {
      "buildOption": {
        "arkOptions": {
          "buildProfileFields": {
            "targetName1": "default1"
          }
        }
      }
    }
  },
]

Change all the key values of buildProfileFields in targets to the same. The following is an example:

"targets": [
  {
    "name": "default",
    "config": {
      "buildOption": {
        "arkOptions": {
          "buildProfileFields": {
            "targetName": "default"
          }
        }
      }
    }
  },
  {
    "name": "default1",
    "config": {
      "buildOption": {
        "arkOptions": {
          "buildProfileFields": {
            "targetName": "default1"
          }
        }
      }
    }
  },
]

Symptom 2

The custom parameter BuildProfile used is marked red by the compiler, and the build fails with "Property xxx does not exist on type 'typeof BuildProfile'." reported.

Solution

Ensure that the user-defined parameter is added to buildProfileFields in build-profile.json5 of the current module.

What Should I Do If PC Stuttering Occurs Due to C++ Project Compilation?

Symptom

For a C++ project with a large amount of code, the CPU usage is high during C++ compilation. As a result, the computer may freeze or respond slowly.

Solution

If a similar problem occurs, perform the following to troubleshoot:

Open the build-profile.json5 file in the module and add the following configuration to arguments: Change the values of compile and link based on the CPU configuration of the computer. You are advised to set the sum of the values of compile and link to half of the number of CPU cores. For example, if the CPU has eight cores, set both compile and link to 2.
"arguments": "-DCMAKE_JOB_POOL_COMPILE:STRING=compile -DCMAKE_JOB_POOL_LINK:STRING=link -DCMAKE_JOB_POOLS:STRING=compile=2;link=2",

It should be noted that if the values of compile and link are changed, the compilation duration may increase.

What Should I Do If the Error Message "A 'undefined symbol' error has occurred" Is Displayed During C++ Compilation?

Symptom

During compilation of a HarmonyOS C++ project, the error message "A 'undefined symbol' error has occurred" is displayed.

Solution

The "undefined symbol" error typically indicates that the linker cannot find the definition of a specific symbol. This issue often occurs when source files are not compiled or linked correctly, or when the necessary library files are missing. To locate and rectify this issue, perform the following steps:

1. Make sure all source files are included in the CMake build.

Check your CMakeLists.txt file to ensure that all relevant source files are included in the project.

Example CMakeLists.txt:
cmake_minimum_required(VERSION 3.10) 
project(MyProject)  
set(CMAKE_CXX_STANDARD 17)  
include_directories(${CMAKE_CURRENT_SOURCE_DIR}                    
                    ${CMAKE_CURRENT_SOURCE_DIR}/include)  
# Add all source files.
add_library(myProgram SHARED main.cpp myLibrary.cpp) 

2. Confirm the symbol definitions in the source files.

Make sure symbols are correctly defined in all relevant source files. For example, check whether myLibrary.cpp includes the definition of myFunction.

myLibrary.cpp

#include "myLibrary.h" 
void myFunction() {     
// Function implementation
}

myLibrary.h

#ifndef MY_LIBRARY_H
#define MY_LIBRARY_H 
void myFunction();  
#endif 

3. Check the compilation and linking order.

Make sure all source files and library files are compiled and linked in the correct order. CMake and Ninja usually handle this order issue, but problems may arise during manual compilation.

4. Clean and regenerate build files.

Sometimes, build files may become corrupted or symbol definitions may be lost. Try cleaning the build directory and regenerating the build files:

hvigorw clean 1 

Alternatively, manually delete the .cxx directory from the module.

5. Check library paths and linker flags.

If using third-party libraries, make sure the library paths and linker flags are correctly configured in the CMakeLists.txt file. Sample code:

cmake_minimum_required(VERSION 3.10) 
project(MyProject)  
set(CMAKE_CXX_STANDARD 17)  
# Ensure that the header file of the involved third-party library is added.
include_directories(${PATH_TO_EXTERNAL_LIBRARY}
                    ${PATH_TO_EXTERNAL_LIBRARY}/include)  
# Add a source file.
add_library(myProgram SHARED main.cpp myLibrary.cpp)  
# Link the third-party library.
target_link_libraries(myProgram PUBLIC /path/to/external/library) 

6. Enable verbose compilation and linking output.

To understand the detailed compilation and linking process, you can enable more verbose output. Add the following to the CMakeLists.txt file:

set(CMAKE_VERBOSE_MAKEFILE ON)

7. Check the Ninja output logs.

By default, Ninja generates a .ninja_log file containing detailed information about the build process. You can check this log file to identify issues that occur during the build process.

cat {module}/.cxx/default/default/arm64-v8a/.ninja_log 

Check the log file for the source file or header file containing the symbols.

8. Use the nm tool to check symbols.

Inspect the symbols in the target file and library file to ensure that the symbol definitions exist.

You can do so with the nm tool in the SDK: sdk/default/openharmony/native/llvm/bin/llvm-nm.

Check the target file.

nm myLibrary.o | grep myFunction 

Check the third-party library file.

nm /path/to/external/library | grep myFunction

Conclusion

By following the above steps, you can locate and resolve the "error: undefined symbol" issue. When compiling a C++ project with CMake, Ninja, and LLVM, ensure that all source files and library files are correctly included in the project and that the compilation and linking options are correctly configured. If the issue persists, consult the compilation and linking output logs for clues to help you identify the specific cause.

What Should I Do If the Error Message "A 'unknown type name' error has occurred" Is Displayed During C++ Compilation?

Symptom

During compilation of a HarmonyOS C++ project, the error message "A 'unknown type name' error has occurred" is displayed.

Solution

This error occurs when the compiler cannot recognize a certain type. This may be due to the type not being defined, the relevant header file not being included, or the path to the included header file being incorrect. To locate and rectify this issue, perform the following steps:

  1. Check for included header files.

    Make sure all necessary header files are correctly included in the source file. For example, if you are using a custom type or a type provided by a library, be sure to include the relevant header file in the file where the type is used.

    Example

    // main.cpp
    #include "myLibrary.h" 
    int main() {
         MyType obj;
         // Use a custom type.
         return 0;
    }
    
    // myLibrary.h
    #ifndef MY_LIBRARY_H
    #define MY_LIBRARY_H
    class MyType {
    public:
         MyType() {}
         void doSomething();
    };
    #endif
  2. Verify header file paths.

    Make sure the search paths for header files are correctly set in the CMakeLists.txt file. You can add header file directories using include_directories.

    Example CMakeLists.txt:

    cmake_minimum_required(VERSION 3.10) 
    project(MyProject)  
    set(CMAKE_CXX_STANDARD 17)  
    # Add a header file directory.
    include_directories(${CMAKE_SOURCE_DIR}/include)  
    # Add a source file.
    add_library(myProgram SHARED src/main.cpp src/myLibrary.cpp) 
  3. Clean and regenerate build files.

    Sometimes, build files may become corrupted or symbol definitions may be lost. Try cleaning the build directory and regenerating the build files:

    hvigorw clean

    Alternatively, manually delete the .cxx directory from the module.

  4. Enable verbose compilation output.

    To understand the detailed compilation process, you can enable more verbose output. Add the following to the CMakeLists.txt file:

    set(CMAKE_VERBOSE_MAKEFILE ON) 
  5. Check the compilation output logs.

    By default, Ninja generates a .ninja_log file containing detailed information about the build process. You can check this log file to identify issues that occur during the build process.

    cat .cxx/default/default/arm64-v8a/.ninja_log
  6. Use CMake's message function for debugging.

    Add the message function in the CMakeLists.txt file to print debugging information to ensure that paths and variables are correctly set.

    Example

    message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}") 
    message(STATUS "Include directories: ${CMAKE_INCLUDE_PATH}") 
  7. If the error-causing API is a system API, check the initial version in the corresponding API reference to confirm whether the API is available in the current version.

Conclusion

By following the above steps, you can locate and resolve the "error: unknown type name" issue. When compiling a C++ project with CMake, Ninja, and LLVM, it is crucial to ensure that all header files are correctly included and that the correct header file paths are set. If the issue persists, consult the compilation output logs for clues to help you identify the specific cause.

What Should I Do If Error Message "LABEL_VALUE_ERROR" Is Displayed?

Symptom

The LABEL_VALUE_ERROR message is displayed during project synchronization or building.

Solution

Set the label field in the config.json file to the resource reference mode.

  1. Choose resources > base > element and add the corresponding character string to the string.json file.
  2. Reference the string resource again in the config.json file.

What Should I Do If Error Message "Schema validate failed" Is Displayed Due to Missing Startup Window Information of an App/Atomic Service?

Symptom

An error occurs during project synchronization or build, and the error message "Schema validate failed" is displayed.

Solution

During app/atomic service development, you can set the icon and background color of the startup window. The startup window settings are automatically configured when you create a project. If you accidentally delete a required field, the system generates an error to alert you and prevent misconfiguration. The following describes how to reset the startup page information. You can customize the icon and background color of the startup page.

To improve the cold start performance of your app/atomic service, you can set the icon and background color on the startup window as follows:

  1. Right-click resources > base > element and choose New > Element Resource File from the shortcut menu to create a resource file.

  2. In the dialog box displayed, name the file, for example, color, and set Root element to color.

    After the creation is complete, the color.json file shown below is displayed.

  3. Copy the color.json file created in 2 to the ohosTest > resources > base > element directory of the module.

  4. Add the startWindowIcon and startWindowBackground fields to the abilities array in the src > main > module.json5 file of the module. If any field is missing, the error message "ERROR: Schema validate failed" is reported. The startWindowIcon field is used to index the icon resource in resources > base > media of the module, and the startWindowBackground field is used to index the color in resources > base > element > color.json.

  5. Add the startWindowIcon and startWindowBackground fields to the abilities array in the src > ohosTest > module.json5 file. The startWindowIcon field is used to index the icon resource in resources > base > media of module ohosTest, and the startWindowBackground field is used to index the color in resources > base > element > color.json.

What Should I Do If the Error Message "Schema validate failed" Is Displayed During Compilation?

Symptom

An error occurs during compilation via DevEco Studio, and the error message "Schema validate failed" is displayed.

Solution

The cause is that some fields are missing or spelled incorrectly in the configuration file. Locate the fault based on the error details.

For example, if name in the abilities tag in module.json5 is misspelled to nam, the following error information is displayed:

	 Detail: Please check the following fields.
{
  instancePath: 'module.abilities[0]',
  keyword: 'required',
  params: { missingProperty: 'name' },
  message: "must have required property 'name'",
  location: 'D:/MyApplication/entry/src/main/module.json5:15:8'
} 
{
  instancePath: 'module.abilities[0]',
  keyword: 'required',
  params: { missingProperty: 'srcEntrance' },
  message: "must have required property 'srcEntrance'",
  location: 'D:/MyApplication/entry/src/main/module.json5:15:8'
} 
{
  instancePath: 'module.abilities[0]',
  keyword: 'required',
  params: { missingProperty: 'name' },
  message: "must have required property 'name'",
  location: 'D:/MyApplication/entry/src/main/module.json5:15:8'
} 
{
  instancePath: 'module.abilities[0]',
  keyword: 'oneOf',
  params: { passingSchemas: null },
  message: 'must match exactly one schema in oneOf',
  location: 'D:/MyApplication/entry/src/main/module.json5:15:8'
} 
{
  instancePath: 'module.abilities[0]',
  keyword: 'enum',
  params: {
    allowedValues: [
      'priority',
      'name',
      'srcEntrance',
      'srcEntry',
      'launchType',
      'description',
      'icon',
      'label',
      'permissions',
      'metadata',
      'visible',
      'exported',
      'skills',
      'backgroundModes',
      'continuable',
      'startWindowIcon',
      'startWindowBackground',
      'removeMissionAfterTerminate',
      'orientation',
      'supportWindowMode',
      'maxWindowRatio',
      'minWindowRatio',
      'maxWindowWidth',
      'minWindowWidth',
      'maxWindowHeight',
      'minWindowHeight',
      'excludeFromMissions'
    ]
  },
  message: 'must be equal to one of the allowed values',
  location: 'D:/MyApplication/entry/src/main/module.json5:15:8'
} 
{
  instancePath: 'module.abilities[0]',
  keyword: 'propertyNames',
  params: { propertyName: 'nam' },
  message: 'property name must be valid',
  location: 'D:/MyApplication/entry/src/main/module.json5:15:8'
} 

Keywords in the preceding error information:

What Should I Do If the Error Message "No available entry module found" Is Displayed During Compilation?

Symptom

An error occurs during compilation via DevEco Studio, and the error message "No available entry module found" is displayed.

Solution

The dependent entry module needs to be configured in the feature module. During compilation, DevEco Studio checks whether the entry module on which the feature module depends exists. If an error similar to above is reported, the possible causes are as follows:

  1. In the build-profile.json5 file of the feature module, the name configured for the entryModules field is different from the actual name of the entry module. In this case, modify the value of entryModules to the name of the entry module.
  2. In the modules field of the project-level build-profile.json5 file, the feature module is placed before the entry module. Since DevEco Studio configures modules from front to back during compilation, if the entry module is not read or configured when the feature module is configured, an error indicating that the entry module does not exist is reported. Place the feature module after the dependent entry module in the modules field.

What Should I Do If the Error Message "keystore password was incorrect" Is Displayed During Compilation?

Symptom

An error occurs during compilation via DevEco Studio, and the error message "keystore password was incorrect" is displayed.

Possible Cause

The password of the keystore (.p12) is incorrect.

storePassword and keyPassword are customized by the developer when the .p12 file is created. Remember the passwords. The build-profile.json5 file of the DevEco Studio project contains the ciphertext of the password. However, the signing tool requires the plaintext of the password. Therefore, the value in the build-profile.json5 file cannot be directly used in the signing tool.

Common Scenarios

  1. Incorrect password.
  2. An actual password is required in the command line, but a ciphertext password is entered by mistake.
  3. The key (keyAlias) password is mixed up with the keystore (.p12) password.

Solution

The cause is that the signature password in the signature file is incorrect.

Developers can solve this problem by re-signing.

1. Choose File > Project Structure > Project > Signing Configs.

2. Select Automatically generate signature, wait for re-signing, and click OK.

What Should I Do If the Error Message "please check deviceType or distroFilter of the module" Is Displayed During Compilation?

Symptom

An error occurs during compilation via DevEco Studio. One of the following messages is displayed:

Solution

Modify the project to ensure that it meets the HAP uniqueness verification logic during packaging. For details, see Logic for Checking HAP Uniqueness.

What Should I Do If the Error Message "Failed to generate test project build system" Is Displayed During Compilation?

Symptom

During multi-module native build, the error message "Failed to generate test project build system." is displayed.

Solution

Delete the .cxx folder under the module that reports the error, select the module to be built, and run the Make Module ${moduleName} command to build the module separately. Do not build multiple modules at the same time.

What Should I Do If the Third-Party Dependency Library of a C/C++ Project Is Not Packaged into the HAP?

Symptom

When a C/C++ project depends on a third-party so. file, the third-party so. file is not packaged into the HAP file after it is generated.

Solution

Currently, DevEco Studio has limited addressing modes for third-party so. files in C/C++ projects. If third-party so. files are not packaged into HAP, modify the so. file import mode.

  1. Define an alias (for example, jsbind_shared_lib_tracing), indicating the third-party so. file to be imported.
  2. Use SHARED IMPORT to define the so. file import mode as dynamic import.
  3. Use IMPORTED_LOCATION to specify the location where the so. file is imported.
  4. Declare the defined three-party so. file to the target.

  5. Generate a HAP again and ensure that the third-party .so file is packaged into the HAP.

What Should I Do If Files in the src/main/cpp Directory of the Static Library Module Are Not Packaged into the HAR?

Symptom

Click Build > Make Module ${libraryName} to compile and build the HAR, files in the cpp directory are not displayed in the build product.

Solution

When Hvigor 2.5.0-s or later is used for HAR compilation and build, only the local dependencies specified in dependencies in the current module are included in the .har file. The dependencies specified in devDependencies are not included.

Move the corresponding local dependency to dependencies and recompile it.

What Should I Do If the Error Message "ArkTS:WARN: For details about ArkTS syntax errors" Is Displayed During Compilation?

Symptom

During project build, the error message "ArkTS:WARN: For details about ArkTS syntax errors, see FAQs" is displayed.

Solution

Check the error message for specific ArkTS syntax rule violations, which are enclosed in brackets, such as (arkts-no-var). Then, refer to the TypeScript to ArkTS Cookbook and modify your code to comply with the ArkTS syntax specifications.

What Should I Do If the Error Message "ninja: error: mkdir(xxx): No such file or directory" Is Displayed During Compilation?

Symptom

An error is reported during native project compilation, and the following warning and error message are displayed:

A warning message is generated indicating that the length of the project directory exceeds 250 characters. For example:

The compilation error message "ninja: error: mkdir(xxx): No such file or directory" is displayed, as shown in the following figure.

Solution

The default value of CMAKE_OBJECT_PATH_MAX is 250. If the actual path length of the object file in the project exceeds this limit, a compilation error is reported.

You need to set CMAKE_OBJECT_PATH_MAX in CMakeLists.txt based on the actual path length of the object file. The procedure is as follows:

What Should I Do If the Error Message "(is the command line too long?)" Is Displayed During Compilation?

Symptom

An error is reported during native project compilation, and the following warning and error message are displayed:

A warning message is generated indicating that the length of the project directory exceeds 250 characters. For example:

The compilation error message "(is the command line too long?)" is displayed, as shown in the following figure.

Solution

The default value of CMAKE_OBJECT_PATH_MAX is 250. If the actual path length of the object file in the project exceeds this limit, a compilation error is reported.

You need to set CMAKE_OBJECT_PATH_MAX in CMakeLists.txt based on the actual path length of the object file. The procedure is as follows:

What Should I Do If the Error Message "CMake Error: The following variables are used in this project, but they are set to NOTFOUND" Is Displayed During Compilation?

Symptom

When find_path is used in a native project, the following error information is displayed:

Solution

In the CMake cross-compilation configuration file (ohos.toolchain.cmake) provided by the OpenHarmony SDK, the search path is restricted to CMAKE_SYSROOT.

If you need to add a search path, use the list API to add a custom path in CMakeLists.txt. For example, add D:demo to the search path.

list(APPEND CMAKE_FIND_ROOT_PATH_MODE_INCLUDE "D:demo")

After the path is added, you can use find_path to search files in the D:demo directory.

What Should I Do If the Error Message "Unknown resource name" Is Displayed During Compilation?

Symptom

In a project, module A references module B. When module A is compiled, an error message "Unknown resource name 'xxxx'" is displayed, indicating that the resources of module B cannot be found.

Solution

Ensure that the following conditions are met:

  1. Resources must be stored in the resource/base directory.
  2. Module B has been installed.
  3. Module A references the resources of module B by the defined module name instead of the relative path.

Symptom

The method of referencing a module is incorrect. If the code of another module is referenced, an error message is displayed, indicating that the resource cannot be found.

Solution

Add the module under dependencies in the oh_package.json5 module.

An example is provided as follows.

Symptom

HSP A applies for a permission that references resources. When all components that depend on HSP A are built, an error message is displayed, indicating that the resources referenced by HSP A cannot be found.

Solution

Manually configure the corresponding resource in the referencing party.

What Should I Do If the Error Message "Task xxx was not found in the project xxx" Is Displayed During Build?

Symptom

When the build command is manually executed on the CLI, the build fails and the error message "Task xxx was not found in the project xxx" is displayed.

Cause Analysis

  1. Run the hvigorw tasks command to check whether the corresponding command exists.
  2. Check whether the type field in module.json5 of the corresponding project matches the command execution module. As shown in the preceding figure, the assembleHar command is used to package the HAR module in the project. If the type field in module.json5 is not har, the preceding error message is displayed.

Solution

  1. Run the correct command.
  2. Check the type field in module.json5 of the corresponding project and run the corresponding command.

What Should I Do If the Error Message "The reason and usedScene attributes are mandatory for user_grant permissions" Is Displayed During Compilation?

Symptom

Compilation via DevEco Studio fails, and the error message "The reason and usedScene attributes are mandatory for user_grant permissions" is displayed.

Possible Causes

In DevEco Studio NEXT Developer Preview2 and later versions, the following rule is added: In an app package, the permission list requestPermissions under the module of all Entry.hap and Feature.hap must be specified. (requestPermissions can be left empty by default. If it is not empty, the name field is mandatory. For the user_grant permission, the reason and usedScene fields are mandatory.)

Solution

Go to the corresponding module.json5 file and supplement the reason and usedScene fields under requestPermissions. The following is an example:

"requestPermissions": [
  {
    "name": "ohos.permission.READ_IMAGEVIDEO",
    "reason": "$string:module_desc",
    "usedScene": {
      "abilities": [
        "EntryAbility"
      ],
      "when": "inuse"
    }
  }
]

What Should I Do If the Error Message "Only one default card can be configured in the form_config.json file" Is Displayed During Compilation?

Symptom

Compilation via DevEco Studio fails, and the error message "Only one default card can be configured in the form_config.json file" is displayed.

Possible Causes

In DevEco Studio NEXT Developer Preview2 and later versions, the following rule is added: In the widget configuration file, isDefault cannot be left empty. Each UIAbility has only one default widget.

Solution

Go to the corresponding module.json5 file, select the default widget, and set the isDefault field of other widgets to false.

What Should I Do If the Error Message "In the form_config.json file, if the value of the updateEnabled field is true, the updateDuration and scheduleUpdateTime fields cannot be both empty" Is Displayed During Compilation?

Symptom

Compilation via DevEco Studio fails, and the error message "In the form_config.json file, if the value of the updateEnabled field is true, the updateDuration and scheduleUpdateTime fields cannot be both empty." is displayed.

Possible Causes

In DevEco Studio NEXT Developer Preview2 and later versions, the following rule is added: updateEnabled in the widget configuration file cannot be left empty. If updateEnabled is set to true, you can select either updateDuration or scheduledUpdateTime and configure it. If both updateDuration and scheduledUpdateTime are configured, updateDuration takes effect first.

Solution

Open the module.json5 file and set updateEnabled to false or add updateDuration and scheduledUpdateTime as required.

What Should I Do If the Error Message "The path XX is not writable. please choose a new location" Is Displayed During Compilation?

Symptom

When DevEco Studio is opened directly from a .dmg file on macOS, any attempt to build a project results in the error message "The path XX is not writable. Please choose a new location."

Possible Causes

Opening DevEco Studio from the .dmg file launches it in read-only mode, and the files built into DevEco Studio do not have write permissions.

Solution

Drag DevEco-Studio.app to Applications and install DevEco Studio by following the onscreen instructions.

What Should I Do If the Error Message "Property 'XX' does not exist on type 'typeof BuildProfile'" Is Displayed During Compilation?

Symptom

The external interface provided by the local HSP module uses a custom parameter BuildProfileFileds, which is not defined in the HAP, and the HAP references this interface, causing the compilation to fail with the message "Property 'XX' does not exist on type 'typeof BuildProfile'".

Solution

You can resolve this issue in two ways:

What Should I Do If the Error Message "The useNormalizedOHMUrl settings of packages xxx and the project useNormalizedOHMUrl: xxx do not match" Is Displayed During Compilation?

Symptom

Error message "The useNormalizedOHMUrl settings of packages xxx and the project useNormalizedOHMUrl: xxx do not match" is displayed during compilation

Solution

When useNormalizedOHMUrl is set to true, the ohmurl uses a new method of concatenation and parsing. As such, it cannot be mixed with the old ohmurl; otherwise, it cannot be recognized at runtime.

You can resolve this issue in two ways:

If the issue persists, the HSP is a local package. In this case, import the HSP by adding it to modules in the project-level build-profile.json5 file. The following is an example:

"modules": [
  {
    name: "hsp",   // HSP dependency
    srcPath: "../MyApplication_stageB/hsp",   // Absolute or relative path of the HSP dependency
  }
]

What Should I Do If the Error message "Could not resolve 'xxx' from" Is Displayed When the 'xxx' Directory Exists?

Symptom

The error message "Could not resolve 'xxx' from" is displayed during compilation, but the xxx directory exists and contains an Index file.

Possible Causes

When referencing a directory, the compiler automatically concatenates a lowercase index file, but the directory contains an uppercase Index file. During compilation in a case-sensitive environment, the index file cannot be found, resulting in an error.

Solution

When referencing a directory, explicitly specify the reference to the Index file in the directory, for example, xxx/Index.

What Should I Do If the User Directory Does Not Contain an .npmrc File?

Symptom

During an attempt to create a project, the error message "Error: The hvigor depends on the npmrc file. Configure the npmrc file first." is displayed.

Possible Causes

There is no .npmrc file in the user directory.

Solution

Create an .npmrc file in your user directory and configure the following information:

registry=https://repo.huaweicloud.com/repository/npm/
@ohos:registry=https://repo.harmonyos.com/npm/

What Should I Do If the Error Message "Error: 'icon' value `$media:icons` invalid value." Is Displayed During Compilation?

Symptom

The error message "Error: 'icon' value `$media:icons` invalid value" is displayed during compilation.

ERROR: Failed :entry:default@CompileResource...
ERROR: Tools execution failed.
Error: ref `$media:icons` don`t be defined.
Error: 'icon' value `$media:icons` invalid value.
at D:\project\process_profile\default\module.json
Detail: Please check the message from tools.

Possible Cause

When a referenced resource does not exist, the file path indicated by the compilation error is the build directory.

Common Scenarios

  1. The resource file is not added.
  2. The resource file is deleted accidentally.

Solution

Search globally for the resource ID indicated by the error to check whether the erroneous resource exists.

What Should I Do If the Error Message "Error: cJSON_Parse failed, please check the JSON file." Is Displayed During Compilation?

Symptom

The error message "Error: cJSON_Parse failed, please check the JSON file" is displayed during compilation.

Possible Cause

The module.json file format is invalid.

Common Scenarios

1. There is an extra comma (,) at the end of the JSON file.

2. The root element is not enclosed in curly braces ({}).

Solution

Verify the format of the JSON file indicated by the error.

What Should I Do If the Error Message "Error: the name 'XXX' can only contain [a-zA-Z0-9_]." Is Displayed During Compilation?

Symptom

The error message "Error: the name 'XXX' can only contain [a-zA-Z0-9_]" is displayed during compilation.

Solution

Verify the file name. The file name can contain only uppercase letters, lowercase letters, digits, and underscores (_).

What Should I Do If the Error Message "Cannot add xxxx items to index" Is Displayed During Compilation?

Symptom

The error message "Cannot add xxxx items to index" is displayed during compilation.

Possible Causes

There is a function within the compiled file that contains a large number of object literals, array literals, and strings, causing the number of items to exceed the limit (65536).

Solution

Check the relevant files and split the functions that have the aforementioned causes.

What Should I Do If the Compilation Hangs with the Error Message Displayed: The modules directory at "xxx/workspace/node_modules" will be removed and reinstalled from scratch. Proceed? (Y/n) > true?

Symptom

The compilation hangs, with the error message displayed: The modules directory at "xxx/workspace/node_modules" will be removed and reinstalled from scratch. Proceed? (Y/n) > true.

Possible Causes

The pnpm version used for installing the build plugin is different from that used by DevEco Studio.

Solution

  1. Use DevEco Studio 26.0.0 or later.
  2. If you are still using the current DevEco Studio version, delete the path mentioned in the error message (in the preceding example, delete the C:\Users\xxxx\.hvigor\project_caches\8e4ab2ae81c130fec666aeb0b81bd299 directory) and the C:\Users\xxxx\.hvigor\wrapper directory.