Build error analyzer

From openharmonyinsight/openharmony-skills · View interactive version

Build error analyzer is an AI agent skill from the GitHub repository openharmonyinsight/openharmony-skills. This skill should be used when the user asks to "分析构建错误", "analyze build errors", "查看编译错误", "检查构建日志", "诊断链接错误", "fix build errors", "resolve compilation errors", "分析 last_error.log", "extract build error", "分析SDK的编译错误", "分析 SDK 编译错误", "analyze SDK build errors", "check SDK errors", "诊断 sdk 编译错误", or

How to use this skill

Skill file

Build Error Analyzer Skill

This skill specializes in analyzing OpenHarmony build errors from last_error.log and providing fix recommendations only (no automatic code modifications) based on error patterns and historical case studies.

IMPORTANT: This skill provides analysis and recommendations ONLY. It does NOT automatically modify code files.

⚠️ CRITICAL WORKFLOW (MUST FOLLOW)

YOU MUST ALWAYS FOLLOW THIS EXACT SEQUENCE:

  1. FIRST: Extract errors from out/<product>/build.log → generates out/<product>/last_error.log
  2. THEN: Read and analyze ONLY from out/<product>/last_error.log
  3. NEVER: Read directly from out/<product>/build.log or any other log files (error.log, build_output*.log, etc.)
  4. SUCCESS CASE: If last_error.log contains "build success" or "no error", STOP and report success

Why?:

Before reading ANY errors, ALWAYS run:

# ⚠️ CRITICAL: First cd to OpenHarmony root directory, then run the script
cd <openharmony_root>
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/<product>/build.log

⚠️ CRITICAL - CHECK FOR SUCCESS FIRST:

After reading last_error.log, if you see:

IMMEDIATELY STOP and report:

## ✅ 构建成功

最新的构建已经成功完成,没有发现任何错误。

**构建状态**: 成功
**错误信息**: 无

建议: 您可以继续进行开发或测试工作。

DO NOT:

Important Path Information

Always use these paths:

⚠️ SPECIAL CASE - SDK Build Paths:

Workflow:

  1. ✅ Extract errors from out/<product>/build.log using the script → creates out/<product>/last_error.log
  2. ✅ For SDK: Extract from out/sdk/build.log → creates out/sdk/last_error.log
  3. ✅ Analyze errors from the extracted last_error.log ONLY
  4. ✅ Provide fix recommendations ONLY - do NOT modify code

Common Mistakes to Avoid:

Behavior Guidelines

This skill provides ANALYSIS and RECOMMENDATIONS ONLY:

✅ DO:

❌ DO NOT:

⚠️ CRITICAL - NEVER SUGGEST CLEARING LTO CACHE:

Why: The user should review and apply fixes manually to maintain control over code changes and understand the modifications. LTO cache issues are extremely rare and clearing caches as first resort masks real problems, wastes rebuild time, and disrupts incremental compilation benefits.

Prerequisites

  1. ⚠️ CRITICAL: ALWAYS extract from out/<product>/build.log FIRST before reading
  2. Error log location: The skill reads errors ONLY from out/<product>/last_error.log (same directory as build.log)
  3. Error extraction: ALWAYS use the extraction script from foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh (from OpenHarmony root) to generate/update last_error.log before reading
  4. Source build.log: Errors are extracted ONLY from out/<product>/build.log in the OpenHarmony output directory
  5. Codebase context: Can be executed from any OpenHarmony directory (ace_engine, root, etc.)
  6. ⚠️ SUCCESS CHECK: If last_error.log contains "build success" or "no error", STOP and report success - DO NOT read other log files like error.log, build_output*.log, etc.
  7. EXCLUSIVE LOG SOURCE: ONLY read from last_error.log - NEVER from error.log, build_output*.log, error.*.log, or any other log files

Analysis Workflow

Step 1: Extract Latest Error (REQUIRED - ALWAYS DO THIS FIRST)

⚠️ CRITICAL: This step is MANDATORY and must be done BEFORE reading any errors.

Why this is required:

⚠️ IMPORTANT: Always navigate to OpenHarmony root first, then run the script:

# Step 1: Navigate to OpenHarmony root directory
cd <openharmony_root>

# Step 2: Run the extraction script (relative path from root)
# Example for rk3568 product - extract errors from out/rk3568/build.log
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/rk3568/build.log

# Example for SDK product - extract errors from out/sdk/build.log (⚠️ SPECIAL CASE: out/sdk/ NOT out/ohos-sdk/)
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/sdk/build.log

# Example for other products:
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/rk3588/build.log

The script will:

⚠️ DO NOT SKIP THIS STEP

Step 2: Read and Categorize Errors

⚠️ CRITICAL: Only read last_error.log from out/<product>/ directory in the OpenHarmony output tree.

After extraction, the error log is located at:

Read the extracted error log:

# Check for last_error.log in common product directories
cat out/rk3568/last_error.log
# or for SDK (⚠️ SPECIAL CASE: out/sdk/ NOT out/ohos-sdk/)
cat out/sdk/last_error.log
# or for other products
cat out/rk3588/last_error.log

⚠️ CRITICAL - CHECK FOR SUCCESS FIRST:

Before any analysis, CHECK if the build succeeded:

If last_error.log contains:

IMMEDIATELY STOP and report:

## ✅ 构建成功

最新的构建已经成功完成,没有发现任何错误。

**构建状态**: 成功
**错误信息**: 无

建议: 您可以继续进行开发或测试工作。

DO NOT continue to:

Only if there are actual errors, proceed to categorize them:

Error Categories:

  1. Compilation errors (CXX tasks) - Syntax, missing headers, incomplete types
  2. Linker errors (SOLINK/LINK tasks) - Undefined symbols, missing libraries
  3. Build system errors - GN/Ninja configuration issues

Step 3: Match Against Known Cases

Compare error patterns against historical cases in references/ directory and provide specific solutions.

Case matching priority:

  1. Match by error signature (e.g., "undefined symbol" + "referred by")
  2. Match by error context (e.g., "timepicker module" usage)
  3. Match by file pattern (e.g., BUILD.gn issues)
  4. Provide general guidance if no specific case matches

Step 4: Provide Fix Recommendations (NO Automatic Modifications)

CRITICAL: This step provides recommendations ONLY. Do NOT use Edit/Write tools to modify code.

Based on error type and matched cases, provide:

Recommended Output Format:

## 构建错误分析

### 错误类型
[编译错误/链接错误/构建系统错误]

### 错误位置
[文件路径:行号]

### 错误信息
[完整的错误消息]

### 根本原因
[详细解释为什么会出现这个错误]

### 修复建议

**文件**: [完整文件路径:行号]

**当前代码**:

[错误代码片段]


**应修改为**:

[正确代码片段]


**修改说明**: [解释为什么要这样修改]

### 验证步骤
1. [第一步验证操作]
2. [第二步验证操作]
3. [如何确认修复成功]

### 参考
[相关的历史案例或文档链接]

DO NOT:

DO:

Error Patterns and Solutions

Pattern 1: Undefined Symbol Errors

Error signature:

ld.lld: error: undefined symbol: <symbol_name>
>>> referenced by <file>:<line>

⚠️ CRITICAL ANALYSIS WORKFLOW (MUST FOLLOW IN ORDER):

When encountering ld.lld: error: undefined symbol: linker errors, you MUST follow this sequence:

Step 1: Identify Which Library is Failing to Link

Check the error message to determine which library has the undefined symbol:

Step 2: Apply the Correct Scenario Based on Library Type

Scenario 1: libace/libace_compatible Main Library Cannot Find Symbol

Symptoms:

Root Cause:

Solution:

  1. Check if implementation exists:

```bash

grep -r "SymbolName" --include="*.cpp" frameworks/

```

  1. If implementation exists, check BUILD.gn:

```bash

grep -r "implementation_file.cpp" frameworks/*/BUILD.gn

```

  1. Add .cpp to BUILD.gn:
  1. Verify with other files:

```bash

# Find where similar files in same directory are compiled

find frameworks/core/components_ng/pattern/<pattern_name>/ -name "*.cpp"

grep "similar_file.cpp" frameworks/core/BUILD.gn

```

Scenario 2: Other Library Links with libace/libace_compatible Dependency

Symptoms:

Root Cause:

⚠️ CRITICAL: Distinguish Non-Template vs Template FIRST

Before applying any solution, determine the type:

undefined symbol error
    ↓
Is it a non-template class method?
    → YES: Use Non-Template Solution (Step 1A)
    → NO: Use Template Solution (Step 1B, see Scenario 3)

Solution (Step-by-Step):

Step 1A: For NON-TEMPLATE class methods ⭐

⚠️ CHECK 1: Does the class have ACE_FORCE_EXPORT?

// Case A: Class WITHOUT ACE_FORCE_EXPORT
class PaddingPropertyF {
    float Width() const;
};

// Case B: Class WITH ACE_FORCE_EXPORT
class ACE_FORCE_EXPORT PaddingPropertyF {
    float Width() const;
};

For Case A (Class WITHOUT export) - PREFERRED METHOD:

Example (PaddingPropertyF case):

// In header file (.h) - Add ACE_FORCE_EXPORT to method declarations
class PaddingPropertyF {
    ACE_FORCE_EXPORT float Width() const;   // ← Add here
    ACE_FORCE_EXPORT float Height() const;  // ← Add here
};

// In implementation file (.cpp) - NO ACE_FORCE_EXPORT here
float PaddingPropertyF::Width() const
{
    return left.value_or(0.0f) + right.value_or(0.0f);
}

float PaddingPropertyF::Height() const
{
    return top.value_or(0.0f) + bottom.value_or(0.0f);
}

For Case B (Class WITH export):

Example:

// In header file (.h) - Class already exported
class ACE_FORCE_EXPORT PaddingPropertyF {  // ← Entire class exported
    float Width() const;   // Automatically exported
    float Height() const;  // Automatically exported
};

// In implementation file (.cpp) - No individual exports needed
float PaddingPropertyF::Width() const { /* implementation */ }

Step 1B: For TEMPLATE class methods/functions (see Scenario 3)

Template-specific rules apply - refer to Scenario 3 for detailed steps.

Step 2: Add to libace.map with fine-grained symbol names ⭐

After adding exports, add the symbol to build/libace.map:

# Check if symbol already in libace.map
grep "ClassName" build/libace.map

Required changes:

Example - Regular Methods:

# In build/libace.map
{
  global:
    # ✅ FINE-GRAINED - Export specific methods (PREFERRED for non-template)
    OHOS::Ace::PaddingPropertyF::Width*;
    OHOS::Ace::PaddingPropertyF::Height*;

    # ⚠️ ACCEPTABLE - Export entire class (if class has ACE_FORCE_EXPORT)
    OHOS::Ace::PaddingPropertyF::*;

    # ⚠️ DIFFERENT - Template patterns (use wildcards)
    void?OHOS::Ace::StringUtils::StringSplitter*;  # Template function
    OHOS::Ace::NG::LayoutConstraintT*;             # Template class
  };
}

Why fine-grained for non-templates?

Common Mistakes (DO NOT do):

Step 3: Verify symbol export:

nm -D out/rk3568/arkui/ace_engine/libace.z.so | grep SymbolName

Common mistakes (DO NOT do):

⚠️ Example of Common Mistake - Over-Exporting:

// ❌ WRONG - Exports entire class when only constructors needed
OHOS::Ace::VelocityTracker::*;  // Exports ALL members unnecessarily

// ✅ CORRECT - Fine-grained constructor export
OHOS::Ace::VelocityTracker::VelocityTracker*;  // Only constructors

When to use each pattern:

Scenario 3: Template Function Instantiation Issues

Symptoms:

Root Cause:

Solution (3 steps required):

Step 1: Add extern template declaration in header (.h)

Add explicit template declaration for new specialization:

// In header file (.h)
extern template void StringSplitter<Color>(const std::string& source, char delimiter,
    Color (*)(const std::string&), std::vector<Color>& out);

Step 2: Add ACE_FORCE_EXPORT to template function declaration

// In header file (.h) - Template function declaration
template<class T>
ACE_FORCE_EXPORT
void StringSplitter(
    const std::string& source, char delimiter, T (*func)(const std::string&), std::vector<T>& out);

Step 3: Add explicit instantiation in .cpp

// In implementation file (.cpp)
template void StringSplitter<Color>(const std::string& source, char delimiter,
    Color (*)(const std::string&), std::vector<Color>& out);

Step 4: Add ACE_FORCE_EXPORT to template implementation

// In implementation file (.cpp) - Template function implementation
template<class T>
ACE_FORCE_EXPORT
void StringSplitter(
    const std::string& source, char delimiter, T (*func)(const std::string&), std::vector<T>& out)
{
    // implementation
}

Step 5: Add to libace.map whitelist

# In build/libace.map
{
  global:
    OHOS::Ace::StringUtils::*;
    void?OHOS::Ace::StringUtils::StringSplitter*;  # Match template instantiations
    void?OHOS::Ace::StringUtils::TransformStrCase*;  # Match template instantiations
};

⚠️ Template Special Notes:

Scenario 4: Special Libraries (Rare Cases)

Symptoms:

Root Cause:

Solution:

Example for libarkoala_native_ani:

# In: frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn
ohos_shared_library("arkoala_native_ani") {
  sources = [
    "//foundation/arkui/ace_engine/frameworks/base/utils/string_utils.cpp",
    "UINode/uinode_module_methods.cpp",
    # ... other sources
  ]
}

Example for ace_ndk:

# In: interfaces/native/BUILD.gn
ohos_shared_library("ace_ndk") {
  sources = [
    "//foundation/arkui/ace_engine/frameworks/base/utils/string_utils.cpp",
    "//foundation/arkui/ace_engine/frameworks/core/accessibility/native_interface_accessibility_impl.cpp",
    # ... other sources
  ]
}

⚠️ IMPORTANT:

Scenario 5: Template Class Method Export Issues

Symptoms:

Example Error:

ld.lld: error: undefined symbol: OHOS::Ace::NG::LayoutConstraintT<float>::UpdateSelfMarginSizeWithCheck(OHOS::Ace::NG::OptionalSize<float> const&)
>>> referenced by slider_layout_algorithm.cpp:212

Root Cause:

Solution:

Step 1: Add ACE_FORCE_EXPORT to method implementation in .cpp

Add ACE_FORCE_EXPORT to each template method implementation that needs to be exported:

// In implementation file (.cpp)
template<typename T>
ACE_FORCE_EXPORT  // ← Add this macro before return type
bool LayoutConstraintT<T>::UpdateSelfMarginSizeWithCheck(const OptionalSize<T>& size)
{
    if (selfIdealSize == size) {
        return false;
    }
    return selfIdealSize.UpdateSizeWithCheck(size);
}

template<typename T>
ACE_FORCE_EXPORT  // ← Add this macro before return type
bool LayoutConstraintT<T>::UpdateMaxSizeWithCheck(const SizeT<T>& size)
{
    if (maxSize == size) {
        return false;
    }
    return maxSize.UpdateSizeWhenSmaller(size);
}

⚠️ Template Method Export Notes:

Step 2: Verify libace.map has wildcard pattern

Check that libace.map includes the template class with wildcard:

# Check libace.map for template class pattern
grep "LayoutConstraintT" build/libace.map

Expected output:

OHOS::Ace::NG::LayoutConstraintT*;

⚠️ libace.map Wildcard Rules:

Step 3: Verify symbol export

# Check if symbol is exported in shared library
nm -D out/rk3568/arkui/ace_engine/libace.z.so | grep LayoutConstraintT

Expected output (should show exported symbols):

0000000000000000 T _ZN2OHOS3Ace2NG14LayoutConstraintTIfE25UpdateSelfMarginSizeWithCheckERKNS0_11OptionalSizeIfEE

⚠️ Common Mistakes:

✅ Correct Approach:

Step 3: Verify the Fix

After applying the appropriate solution:

# 1. Navigate to OpenHarmony root and rebuild
cd <openharmony_root>
./build.sh --product-name rk3568 --build-target ace_engine

# 2. Check if symbol is now exported (for scenarios 2-3)
nm -D out/rk3568/arkui/ace_engine/libace.z.so | grep SymbolName

# 3. Extract new errors
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/rk3568/build.log

# 4. Check result
cat out/rk3568/last_error.log

# For SDK builds (⚠️ use out/sdk/ directory):
# 1. Build SDK: ./build.sh --product-name ohos-sdk --ccache
# 2. Extract errors: foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/sdk/build.log
# 3. Check result: cat out/sdk/last_error.log

Common mistakes (DO NOT do):

⚠️ CRITICAL - CACHE CLEARING IS FORBIDDEN:

Other common mistakes:

✅ ALWAYS do:

Pattern 2: Incomplete Type Errors

Error signature:

error: member access into incomplete type 'const ClassName'
error: invalid use of incomplete type 'class ClassName'
error: member access into incomplete type 'OHOS::Ace::Animator'
    rawPtr_->IncRefCount();

Common causes:

  1. Missing header include
  2. Forward declaration without full definition
  3. RefPtr<T> as class member without proper implementation separation
  4. Header file optimization issues

⚠️ SPECIAL CASE: RefPtr<T> as Class Member

When encountering incomplete type errors with RefPtr<T> or WeakPtr<T> as class members:

DO NOT simply add the full include to the header file. Instead:

```cpp

AnimatableColor(); // Declaration only

~AnimatableColor(); // Declaration only

AnimatableColor(const AnimatableColor& color); // Declaration only

```

```cpp

// animatable_color.cpp

#include "core/animation/animator.h" // Full definition here

AnimatableColor::AnimatableColor() = default;

AnimatableColor::~AnimatableColor() = default;

AnimatableColor::AnimatableColor(const AnimatableColor& color) = default;

```

See: references/forward-declaration-refptr-member.md for detailed solution

Pattern 3: Redefinition Errors

Error signature:

error: redefinition of 'symbol_name'

Common causes:

  1. Multiple definitions across translation units
  2. Missing inline/constexpr for header-only definitions
  3. ODR violations

Historical Cases

All cases are organized by problem type in references/ directory.

Case 1: Undefined Symbol - Missing .cpp Files

Location: references/undefined-symbol-missing-cpp.md

Error signature:

ld.lld: error: undefined symbol: OHOS::Ace::TextTheme::Builder::Build
ld.lld: error: undefined symbol: OHOS::Ace::AdvancedTextStyle::GetGradient

Common causes:

Solution: Add .cpp to both component BUILD.gn AND frameworks/core/BUILD.gn xx_ng_source_set

Case 2: Symbol Export - ACE_FORCE_EXPORT Missing

Location: references/symbol-export-ace-force-export.md

Error signature:

ld.lld: error: undefined symbol: OHOS::Ace::NG::DialogTypeMargin::UpdateDialogMargin
>>> referenced by dialog_button.cpp (timepicker module)

Common causes:

Solution: Add ACE_FORCE_EXPORT to header declaration and add to build/libace.map

Case 3: Symbol Export - libace.map Whitelist

Location: references/symbol-export-libace-map.md

Error signature:

ld.lld: error: undefined symbol: OHOS::Ace::NG::ClassName::MethodName

Context: Symbol has ACE_FORCE_EXPORT but still not exported

Common causes:

Solution: Add symbol to build/libace.map with correct format: OHOS::Ace::NG::ClassName::MethodName*;

Case 4: Redefinition - inline constexpr

Location: references/redefinition-error-constexpr.md

Error signature:

error: redefinition of 'DRAG_BACKGROUND_OPACITY'
error: redefinition of 'URL_DISA_OPACITY'

Common causes:

Solution: Remove duplicate definition from .cpp, keep only inline constexpr in header

Case 5: Build System - ace_core_ng_source_set

Location: references/build-system-ace-core-ng-source-set.md

Error signature:

ld.lld: error: undefined symbol

Context: File exists in component BUILD.gn but symbol still undefined

Common causes:

Solution: Add file to ace_core_ng_source_set template in frameworks/core/BUILD.gn

Case 6: RefPtr<T> Member - Forward Declaration Optimization

Location: references/forward-declaration-refptr-member.md

Error signature:

error: member access into incomplete type 'OHOS::Ace::Animator'
    rawPtr_->IncRefCount();
note: in instantiation of member function 'OHOS::Ace::RefPtr<OHOS::Ace::Animator>::RefPtr'

Context: RefPtr<Animator> or WeakPtr<T> used as class member variable

Common causes:

Correct Solution: DO NOT revert forward declaration! Use implementation separation:

  1. Keep forward declaration in header: class Animator;
  2. Declare special member functions in header (without = default)
  3. Implement them in .cpp file with = default
  4. Include full definition in .cpp file

Benefits: Reduced header dependencies, faster compilation (57% improvement in example)

Case 7: Test Linking - Missing Source Files

Location: references/test-missing-source-files.md

Error signature:

ld.lld: error: undefined symbol: OHOS::Ace::ClassName::MethodName(...)
>>> referenced by test_file.cpp:123

Context: Linking test executable (e.g., xxx_unittest)

Common causes:

Common missing files:

Solution: Add missing .cpp files to appropriate sources based on test template type:

⚠️ Critical: Only add source files, do NOT modify cflags/configs/defines

Case 8: Struct RefPtr Member - Helper Method Pattern

Location: references/forward-declaration-struct-helper-method.md

Error signature:

error: member access into incomplete type 'OHOS::Ace::PixelMap'
    shadowInfo.pixelMap->GetPixelMapSharedPtr()
                         ^
note: forward declaration of 'OHOS::Ace::PixelMap'
class PixelMap;

Context: Pure data structure (POD struct) contains RefPtr<T> member and needs -> access

Common causes:

Root Cause:

Solution: Add helper method to encapsulate type access:

  1. Declare helper method in struct: std::shared_ptr<::OHOS::Media::PixelMap> GetPixelMapSharedPtr() const;
  2. Create new implementation file (e.g., interaction_data.cpp)
  3. Implement helper method in .cpp with full include: #include "base/image/pixel_map.h"
  4. Update usage to call helper method instead of direct -> access
  5. Add new .cpp to BUILD.gn source set

Advanced Scenario (when helper method is not enough):

Key Points:

Case 9: Namespace Type Resolution - Missing Qualifier

Location: references/namespace-ambiguous-type-resolution.md

Error signature:

error: no member named 'DragEvent' in namespace 'OHOS::Ace'
using OnDragStartFunc = std::function<DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>;
                                      ~~~~~~~~~~~~~^

Context: Type defined in parent namespace, used in child namespace

Common causes:

Root Cause:

Correct Solutions (in priority order):

  1. Preserve full namespace qualifier (RECOMMENDED):

```cpp

// In OHOS::Ace::NG namespace

using OnDragStartFunc = std::function<DragDropBaseInfo(

const RefPtr<OHOS::Ace::DragEvent>&, // ✅ Keep full namespace

const std::string&)>;

```

  1. Add forward declaration in correct namespace:

```cpp

// In header, before OHOS::Ace::NG namespace

namespace OHOS::Ace {

class DragEvent; // ✅ Forward declare in correct namespace

}

// In OHOS::Ace::NG namespace

using OnDragStartFunc = std::function<DragDropBaseInfo(

const RefPtr<OHOS::Ace::DragEvent>&, // Still need full namespace

const std::string&)>;

```

  1. Add header dependency (when complete type needed):

```cpp

#include "core/components_ng/event/drag_event.h"

// In OHOS::Ace::NG namespace

using OnDragStartFunc = std::function<DragDropBaseInfo(

const RefPtr<OHOS::Ace::DragEvent>&, // Still use full namespace

const std::string&)>;

```

⚠️ Critical:

Key Points:

When to use:

Case 9: LTO Virtual Thunk - libace.map Export

Location: references/lto-virtual-thunk-libace-map-export.md

Error signature:

ld.lld: error: undefined symbol: virtual thunk to OHOS::Ace::TouchEventTarget::~TouchEventTarget()
>>> referenced by ld-temp.o
>>>               lto.tmp:(construction vtable for OHOS::Ace::TouchEventTarget-in-OHOS::Ace::V2::ListScrollBarController)
>>> referenced by ld-temp.o
>>>               lto.tmp:(construction vtable for OHOS::Ace::TouchEventTarget-in-OHOS::Ace::VerticalDragRecognizer)

Context: Class with virtual functions used as base class, destructor declared in header and implemented in .cpp (forward declaration optimization), LTO (Link Time Optimization) enabled

Common causes:

Root Cause:

Solution: Keep forward declaration optimization, add libace.map exports:

  1. Keep destructor in .cpp file: ~TouchEventTarget() override; in header, implementation in .cpp
  2. Add to libace.map:
  1. DO NOT revert to inline definition in header

Key Points:

Why This Works:

  1. Compilation phase: Header uses forward declaration, .cpp has implementation
  2. LTO link phase: LTO optimizes vtables, creates virtual thunks
  3. Symbol export: libace.maps patterns match virtual thunks, export to dynamic symbol table
  4. Runtime: Derived class vtables can reference virtual thunks correctly

When to use:

Common Mistakes:

Case 10: MinGW - dllexport Declaration Mismatch

Location: references/mingw-dllexport-declaration-mismatch.md

Error signature:

error: redeclaration of 'OHOS::Ace::NG::PaddingPropertyT::SetEdges' cannot add 'dllexport' attribute
void PaddingPropertyT<T>::SetEdges(const T& leftValue, const T& rightValue, const T& topValue, const T& bottomValue)
                          ^
note: previous declaration is here
    void SetEdges(const T& leftValue, const T& rightValue, const T& topValue, const T& bottomValue);
         ^

Context: MinGW/Windows platform compilation only

Key features:

Common causes:

Root Cause:

Solution: Add ACE_FORCE_EXPORT to ALL overloaded method declarations in header:

// Header file - add to ALL declarations
ACE_FORCE_EXPORT void SetEdges(const T& padding);
ACE_FORCE_EXPORT void SetEdges(const T&, const T&, const T&, const T&);  // ✅ Don't forget
ACE_FORCE_EXPORT bool operator==(const PaddingPropertyT& value) const;
ACE_FORCE_EXPORT bool operator!=(const PaddingPropertyT& value) const;  // ✅ Don't forget

Key Points:

When to use:

Prevention checklist:

  1. ✅ Confirm need for export (cross-module usage)
  2. ✅ Add ACE_FORCE_EXPORT to ALL header declarations
  3. ✅ Add ACE_FORCE_EXPORT to ALL .cpp definitions
  4. ✅ Check all overloaded versions (don't miss any)
  5. ✅ Test compilation on MinGW platform

Case 11: std::function<RefPtr<T>> Forward Declaration

Location: references/case-std-function-refptr-forward-declaration.md

Error signature:

error: no member named 'DragEvent' in namespace 'OHOS::Ace'
using OnDragStartFunc = std::function<DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>;
                                                                    ~~~~~~~~~~~^

Context: std::function template using RefPtr<T> as parameter type

Key features:

Common causes:

Root Cause:

Solution: Use forward declaration in header, full definition in .cpp:

// Header file (gesture_event_hub.h)
namespace OHOS::Ace {
class DragEvent;  // ✅ Forward declaration only
}

namespace OHOS::Ace::NG {
// Type alias - NO template instantiation here
using OnDragStartFunc = std::function<DragDropBaseInfo(
    const RefPtr<OHOS::Ace::DragEvent>&,  // ✅ Works with forward decl
    const std::string&)>;
}

// Implementation file (gesture_event_hub.cpp)
#include "core/gestures/drag_event.h"  // ✅ Full definition here

// Actual usage - template instantiation happens here
OnDragStartFunc callback = ...;

Key Principles:

When to use:

Comparison with Related Cases:

Benefits:

Real-World Example: OpenHarmony ACE Engine - gesture_event_hub.h optimization successfully uses forward declaration with std::function<RefPtr<OHOS::Ace::DragEvent>>

Analysis Commands

Check Symbol Existence

# Search for symbol definition in codebase
grep -r "SymbolName" --include="*.h" --include="*.cpp" frameworks/

# Check if .cpp file exists
find frameworks/ -name "implementation_file.cpp"

Verify Build Configuration

# Check if file in BUILD.gn
grep -r "implementation_file.cpp" frameworks/*/BUILD.gn

# Check ace_core_ng source set
grep -A 100 "ace_core_ng_source_set" frameworks/core/BUILD.gn | grep "implementation_file.cpp"

Check Symbol Export

# Check if symbol exported in shared library
nm -D out/rk3568/arkui/ace_engine/libace.z.so | grep SymbolName

# Check libace.map
grep "SymbolName" build/libace.map

Troubleshooting Guide

For New .cpp Files

  1. Create implementation file (.cpp)
  2. Add to component's BUILD.gn
  3. Add to frameworks/core/BUILD.gn ace_core_ng_source_set (if used by libace.z.so)
  4. If symbol is cross-module used:

For Header Optimization Issues

  1. Check for forward declarations used incorrectly
  2. Ensure complete types available where needed
  3. Use inline constexpr for header-only constants
  4. Avoid ODR violations

For Link Errors

  1. Identify missing symbol from error message
  2. Find symbol definition location
  3. Verify implementation is compiled (in BUILD.gn)
  4. Check symbol visibility/export if cross-module
  5. Verify linking order and dependencies

Best Practices

⚠️ CRITICAL RULE - NEVER Clear LTO Cache or Suggest "Clean Build"

⚠️ ABSOLUTE PROHIBITION - When encountering ANY build errors:

Rule Description:

NEVER, UNDER ANY CIRCUMSTANCES, suggest clearing LTO cache, deleting build directories, or performing a "clean build" as the first or primary solution.

What is STRICTLY FORBIDDEN:

Why this is FORBIDDEN:

  1. LTO cache issues are EXTREMELY RARE - 99.9% of build errors are code/configuration issues, not cache problems
  2. Masking real problems - Clearing cache temporarily hides issues without fixing root causes
  3. Wastes massive time - Full rebuilds take hours; incremental builds take minutes
  4. Disables incremental compilation benefits - Future builds become slower
  5. Breaks reproducibility - Makes debugging harder by destroying build state
  6. Lazy diagnosis - Suggesting cache clearing indicates insufficient error analysis

Remember: Real build errors have real causes. Find them, fix them. Don't blame the cache.


0. ⭐ HIGH PRIORITY RULE - Header File Missing Error Resolution

⚠️ CRITICAL RULE - When encountering "file not found" or "no such file or directory" header errors:

Rule Description:

When compilation fails due to missing header files, ALWAYS follow this priority order:

  1. PREFERRED Solution: Add the missing header to the .cpp file that has the error (NOT the optimized header)
  2. LAST RESORT: Only consider modifying optimized headers after user confirmation

Why this rule?:

How to Detect Optimized Headers:

Before suggesting any header modifications, CHECK if the header file is in an optimization state:

# Check 1: Staged changes (暂存状态)
git status --porcelain | grep "^M.*\.h$"

# Check 2: Modified but not staged (修改状态)
git status --porcelain | grep "^ M.*\.h$"

# Check 3: Recent commit (最近一笔提交)
git log -1 --name-only --pretty=format:"" | grep "\.h$"

# Combined check - all three states:
git status --porcelain | grep "\.h$"  # Staged or modified
git diff HEAD~1 --name-only | grep "\.h$"  # Changed in last commit

If the header is in ANY of these states:

When to add to .cpp file (PREFERRED):

// ✅ CORRECT - Add to the .cpp file with the compilation error
// frameworks/core/components_ng/pattern/search/search_gesture_event_hub.cpp
#include "core/events/click_event.h"  // Add missing header here

// ❌ WRONG - Do NOT add back to optimized headers
// frameworks/core/components_ng/event/click_event.h
// #include "core/pipeline/base/element.h"  // Don't restore deleted dependencies

User Confirmation Template (when header modification might be necessary):

⚠️ 检测到 [header_name.h] 可能正在被优化(状态:暂存/修改/最近提交)

编译错误:[error_message]
缺失头文件:[missing_header.h]
错误位置:[error_file.cpp:line]

建议方案:
✅ 方案1(推荐):在 [error_file.cpp] 中添加 #include "[missing_header.h]"
   - 保持头文件优化成果
   - 不增加头文件依赖
   - 符合最佳实践

⚠️ 方案2(需确认):在 [header_name.h] 中添加回 #include "[missing_header.h]"
   - 可能影响编译性能优化
   - 需要用户确认必要性

请确认是否使用方案1,或说明为何需要方案2?

Examples of optimized headers (do NOT modify without confirmation):

Detection Workflow:

Step 1: When encountering "file not found" error

# Extract the missing header path from error
# Example: error: 'core/pipeline/base/element.h' file not found

Step 2: Check if the referencing file is an optimized header

# Find where this error occurs
grep -r "#include.*element.h" frameworks/core/components_ng/event/click_event.h

# Check if click_event.h is being optimized
git status --porcelain | grep "click_event.h"
git log -1 --name-only | grep "click_event.h"

Step 3: Apply the appropriate solution

Verification steps:

  1. Check git status for staged/modified headers
  2. Check last commit for header changes
  3. Identify the .cpp file with the compilation error
  4. Add the missing #include to that .cpp file (PREFERRED)
  5. Verify the fix resolves the error
  6. If header modification was necessary, document why

Key Principles:

Related Skills:

Related Cases:

1. ⭐ HIGH PRIORITY RULE - Type Namespace Confusion (PixelMap, etc.)

⚠️ CRITICAL RULE - When encountering type mismatch errors with common class names:

Rule Description:

When error messages show type mismatches for common class names (like PixelMap), ALWAYS verify you're using the correct namespace variant for the code location.

Common Pitfall - PixelMap Namespace Confusion:

In ACE Engine frameworks (frameworks/core/components_ng/, etc.):

Why this happens:

Solution Pattern:

  1. Identify the error location:
  1. Use correct type:

```cpp

// ✅ CORRECT for frameworks/

#include "base/image/pixel_map.h"

RefPtr<PixelMap> pixelMap_; // OHOS::Ace::PixelMap

// ❌ WRONG in frameworks/

#include "native_image/imageinfo.h" // Don't include media headers

RefPtr<Media::PixelMap> pixelMap_; // Wrong namespace

```

  1. Fix all occurrences:

```bash

# Find wrong usage

grep -rn "Media::PixelMap" frameworks/core/components_ng/

# Replace with correct type

# Media::PixelMap → PixelMap (or OHOS::Ace::PixelMap)

```

When to apply this rule:

DO NOT:

Verification:

  1. Check include: #include "base/image/pixel_map.h" present
  2. Verify usage: RefPtr<PixelMap> or RefPtr<OHOS::Ace::PixelMap>
  3. No Media::PixelMap references in framework code
  4. Virtual function return types match base class

Related Patterns:

2. Build System Architecture

2. Symbol Export Rules ⭐

⚠️ CRITICAL - RULES FOR NON-TEMPLATE CLASSES AND NON-TEMPLATE METHODS:

When encountering "undefined symbol" linker errors for non-template classes and non-template methods, follow these rules in order:

Rule 1: Check if class has ACE_FORCE_EXPORT

First, check if the class definition has ACE_FORCE_EXPORT:

// Case A: Class WITHOUT ACE_FORCE_EXPORT
class PaddingPropertyF {  // ← No export on class
    float Width() const;
};

// Case B: Class WITH ACE_FORCE_EXPORT
class ACE_FORCE_EXPORT PaddingPropertyF {  // ← Export on entire class
    float Width() const;
};

Rule 2: Apply export based on class export status

Case A - Class WITHOUT ACE_FORCE_EXPORT:

// ✅ CORRECT - Add to header declaration
// interfaces/inner_api/ace_kit/include/ui/properties/ng/measure_property.h
class PaddingPropertyF {
    ACE_FORCE_EXPORT float Width() const;  // ← Add here
    ACE_FORCE_EXPORT float Height() const; // ← Add here
};

// frameworks/core/components_ng/property/measure_property.cpp
// NO ACE_FORCE_EXPORT here
float PaddingPropertyF::Width() const { /* implementation */ }

Case B - Class WITH ACE_FORCE_EXPORT:

// ✅ CORRECT - No individual method exports needed
class ACE_FORCE_EXPORT PaddingPropertyF {  // ← Entire class exported
    float Width() const;   // Automatically exported
    float Height() const;  // Automatically exported
};

Rule 3: Add to libace.map with fine-grained symbol names ⭐

⚠️ CRITICAL: ALWAYS prefer fine-grained symbol export as the FIRST choice

After applying Rule 1 and Rule 2, add the symbol to build/libace.map:

// build/libace.map
{
  global:
    // ✅ FINE-GRAINED - Export specific methods (PREFERRED - ALWAYS TRY THIS FIRST)
    OHOS::Ace::PaddingPropertyF::Width*;
    OHOS::Ace::PaddingPropertyF::Height*;

    // ✅ FINE-GRAINED CONSTRUCTORS - Match all constructor overloads
    OHOS::Ace::VelocityTracker::VelocityTracker*;  // Matches both constructors

    // ⚠️ ACCEPTABLE - Export entire class (ONLY if fine-grained not feasible)
    OHOS::Ace::PaddingPropertyF::*;
};

Fine-Grained Export Pattern Priority (in order of preference):

  1. Method-level (MOST PREFERRED):

```

OHOS::Ace::ClassName::MethodName*; # Single method

```

  1. Constructor-level (CONSTRUCTORS):

```

OHOS::Ace::ClassName::ClassName*; # All constructor overloads

```

  1. Class-level (LAST RESORT):

```

OHOS::Ace::ClassName::*; # All class members (use sparingly)

```

Why fine-grained export? ⭐

Decision Tree:

Linker Error: undefined symbol ClassName::MethodName
    ↓
Is ClassName a non-template class?
    YES → Is class declaration has ACE_FORCE_EXPORT?
        YES → ✅ Class already exported
              → Add ClassName::* to libace.map
              → DONE (no individual method exports needed)
        NO → ✅ Add ACE_FORCE_EXPORT to method declaration in .h
             → Add ClassName::MethodName* to libace.map
             → DONE
    NO → Use template export rules (see below)

Comparison: Non-Template vs Template

| Aspect | Non-Template Class/Method | Template Class/Method |

|--------|--------------------------|----------------------|

| Export location | Method declaration in .h (Rule 2) | Both declaration in .h AND definition in .cpp |

| Class export | Covers all methods if present | Individual methods still need export |

| libace.map | Fine-grained: ClassName::MethodName*; | Wildcard: ClassName*; or TemplateFunction*; |

| Reference | This section (Rule 2) | Pattern 1, Scenario 3 & 5 |


⚠️ TEMPLATE-ONLY RULES (NOT for non-template):

For template classes and template functions ONLY, use different rules:

Template functions (Pattern 1, Scenario 3):

Template class methods (Pattern 1, Scenario 5):

DO NOT mix rules:

3. Header Optimization

⭐ Key Principles - Symbol Export for Cross-Module Usage

When encountering "undefined symbol" linker errors for methods used by other dynamic libraries:

⚠️ IMPORTANT: Distinguish Between Non-Template and Template

Before applying any export rules, FIRST determine the type:

Linker Error: undefined symbol
    ↓
Is it a non-template class method?
    → YES: Use Non-Template Rules (below)
    → NO: Use Template Rules (Pattern 1, Scenario 3 & 5)

Non-Template Class Methods: Export at Declaration ⭐

✅ PREFERRED for Non-Template - Add ACE_FORCE_EXPORT to method declaration in header (.h):

// interfaces/inner_api/ace_kit/include/ui/properties/ng/measure_property.h
class PaddingPropertyF {
    ACE_FORCE_EXPORT float Width() const;   // ← Add here (PREFERRED)
    ACE_FORCE_EXPORT float Height() const;  // ← Add here (PREFERRED)
};

// frameworks/core/components_ng/property/measure_property.cpp
// NO ACE_FORCE_EXPORT here for non-template methods
float PaddingPropertyF::Width() const
{
    return left.value_or(0.0f) + right.value_or(0.0f);
}

Why this approach for non-templates?

  1. Fine-grained export control - Export only needed methods
  2. Clear API boundaries - Declaration shows what's exported
  3. Works with libace.map fine-grained rules - Export specific symbols
  4. Consistent with class export semantics - If class has export, no need for individual exports

⚠️ CRITICAL: Check Class Export Status First

// Case A: Class WITHOUT export → Add to individual method declarations
class PaddingPropertyF {
    ACE_FORCE_EXPORT float Width() const;  // ← Required
};

// Case B: Class WITH export → No individual exports needed
class ACE_FORCE_EXPORT PaddingPropertyF {  // ← Entire class exported
    float Width() const;  // Automatically exported, no ACE_FORCE_EXPORT needed
};

❌ DO NOT for Non-Template:

Template-Only: Different Rules Apply ⚠️

For template classes and template functions, use DIFFERENT rules (see Pattern 1, Scenarios 3 & 5):

| Rule Type | Non-Template | Template |

|-----------|--------------|----------|

| Export location | Method declaration in .h | BOTH declaration in .h AND definition in .cpp |

| Class export sufficient? | YES (covers all methods) | NO (individual methods need export) |

| libace.map pattern | Fine-grained: ClassName::MethodName*; | Wildcard: ClassName*; |

| Reference | This section | Pattern 1, Scenarios 3 & 5 |

When to Use Each Approach

| Scenario | Recommended Location | Example |

|----------|---------------------|---------|

| Non-template class method | Method declaration in .h | PaddingPropertyF::Width() |

| Template class method | Both declaration in .h AND implementation in .cpp | LayoutConstraintT<T>::UpdateMaxSizeWithCheck() |

| Template function | Both declaration in .h AND implementation in .cpp | StringUtils::StringSplitter<T> |

| Free function (non-template) | Method declaration in .h | StringUtils::TransformStrCase<std::string> |

| Class with export already | None needed | All methods auto-exported |

Real-World Success Cases

  1. Non-Template Methods (PaddingPropertyF):
  1. Template Class Methods (LayoutConstraintT):
  1. Template Functions (StringUtils):

Remember: When fixing linker errors for symbols needed by other modules, try the .cpp implementation approach first before modifying headers.

4. Template Explicit Instantiation ⭐

For template classes with explicit instantiation:

Issue: PaddingPropertyT<CalcLength> symbols not exported, but PaddingPropertyT<Dimension> works

Root Cause: When a type is used as template parameter for explicit instantiation, the type itself must have export attribute

Key Principle:

Template Type Visibility (CalcLength)
    ↓
Template Specialization (PaddingPropertyT<CalcLength>)
    ↓
Symbol Export Success/Failure

Solution:

// ❌ BEFORE - Type missing export (fails when used as template parameter)
class CalcLength {
    std::string ToString() const { /* inline */ }
};

// ✅ AFTER - Add type-level export (required for template parameters)
class ACE_FORCE_EXPORT CalcLength {  // ← Required when used as template type
    std::string ToString() const { /* inline - keep in header */ }
};

Critical Rules:

  1. Type used as template parameter MUST have export (if type has inline methods)
  2. DO NOT move inline methods to .cpp - keep header optimization
  3. Template methods still need ACE_FORCE_EXPORT in .cpp
  4. Explicit instantiation in .cpp required

When Type-Level Export is Required:

Reference: See references/template-instantiation-type-export.md for detailed case study

⚠️ IMPORTANT - Header Optimization:

Verification Steps

After user applies the recommended fixes, suggest these verification commands:

# 1. Navigate to OpenHarmony root directory and rebuild
cd <openharmony_root>
./build.sh --product-name rk3568 --build-target ace_engine --ccache

# 2. Check for link errors in out/<product>/build.log
grep "ld.lld: error:" out/rk3568/build.log | wc -l

# 3. Verify symbol export (if applicable)
nm -D out/rk3568/arkui/ace_engine/libace.z.so | grep SymbolName

# 4. Extract and check new errors from out/<product>/build.log
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/rk3568/build.log

# 5. Read the extracted errors:
cat out/rk3568/last_error.log

# For SDK builds (⚠️ use out/sdk/ directory):
# 1. Build SDK: ./build.sh --product-name ohos-sdk --ccache
# 2. Check errors: grep "error:" out/sdk/build.log | tail -50
# 3. Extract errors: foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/sdk/build.log
# 4. Read errors: cat out/sdk/last_error.log

Note: These are suggestions for the user to run manually. Do not execute build commands automatically.

Adding New Cases

When solving new build errors:

  1. Document the error in examples/<case-name>.md
  2. Include:
  1. Update this SKILL.md to reference the new case
  2. Add patterns to "Error Patterns and Solutions" section

Example Usage

Example 1: Successful Build (NO ERRORS)

User: "帮我分析一下构建错误"
Assistant: "I'll analyze the build errors from the OpenHarmony output directory.

⚠️ FIRST, I'll extract the latest errors from build.log:

[STEP 1 - NAVIGATE TO ROOT]
cd <openharmony_root>

[STEP 2 - EXTRACTION - MANDATORY]
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/rk3568/build.log

Output:
Extracted latest error block (24 bytes) from out/rk3568/build.log
→ Saved to out/rk3568/last_error.log

[STEP 3 - READ EXTRACTED ERRORS]
Reading out/rk3568/last_error.log...

Content:
build success, no error

[STEP 4 - CHECK FOR SUCCESS]
✅ Build is successful! No errors found.

## ✅ 构建成功

最新的构建已经成功完成,没有发现任何错误。

**构建状态**: 成功
**错误信息**: 无

建议: 您可以继续进行开发或测试工作。

[STOP - DO NOT read other log files like error.log]"

Example 2: Build with Errors

User: "帮我分析一下构建错误"
Assistant: "I'll analyze the build errors from the OpenHarmony output directory.

⚠️ FIRST, I'll extract the latest errors from build.log:

[STEP 1 - NAVIGATE TO ROOT]
cd <openharmony_root>

[STEP 2 - EXTRACTION - MANDATORY]
foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/rk3568/build.log

Output:
Extracted latest error block (12345 bytes) from out/rk3568/build.log
→ Saved to out/rk3568/last_error.log

[STEP 3 - READ EXTRACTED ERRORS]
Reading out/rk3568/last_error.log...

[STEP 4 - CATEGORIZE]
Identified as: compilation error - undeclared identifier

[STEP 5 - MATCH PATTERNS]
Checking references/ directory for similar patterns...
Found match: references/undefined-symbol-missing-cpp.md

[STEP 6 - PROVIDE RECOMMENDATIONS]
Providing detailed fix recommendations (NOT modifying files)

## 构建错误分析

### 错误类型
编译错误 - 未声明的标识符

### 错误位置
frameworks/core/event/touch_event.cpp:25

### 根本原因
函数被删除但调用点未移除:TouchPoint::CovertId() 已删除,但头文件中仍有声明且多处调用

### 修复建议

**选项1: 恢复函数实现** (推荐)

在 frameworks/core/event/touch_event.cpp 中恢复函数:

**当前代码**: (函数已删除)

**应添加**:

void TouchPoint::CovertId()

{

if (sourceTool == SourceTool::PEN) {

originalId = TOUCH_TOOL_BASE_ID + static_cast<int32_t>(sourceTool);

id = id + originalId;

}

}


**选项2: 完全移除函数**

需要修改以下文件:
1. 删除头文件声明: interfaces/inner_api/ace_kit/include/ui/event/touch_event.h:59
2. 移除调用点: adapter/ohos/entrance/mmi_event_convertor.cpp:240
3. 移除测试用例: test/unittest/core/event/touch_event_test_ng.cpp:668

### 验证步骤
1. 重新编译: ./build.sh --product-name rk3568 --build-target ace_engine
2. 重新提取错误: foundation/arkui/ace_engine/.claude/skills/build-error-analyzer/script/extract_last_error.sh out/rk3568/build.log
3. 检查结果: cat out/rk3568/last_error.log

[NOTE: Only providing recommendations, NOT modifying files]"

Key Points:

Version History

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.