重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
arkts-development by fadinglight9291117/arkts_skills
npx skills add https://github.com/fadinglight9291117/arkts_skills --skill arkts-development使用 ArkTS 和 ArkUI 声明式 UI 框架构建 HarmonyOS 应用。
创建一个基础组件:
@Entry
@Component
struct HelloWorld {
@State message: string = 'Hello, ArkTS!';
build() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
Button('Click Me')
.onClick(() => { this.message = 'Button Clicked!'; })
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
| 装饰器 | 用法 | 描述 |
|---|---|---|
@State | @State count: number = 0 | 组件内部状态 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
@Prop@Prop title: string |
| 父组件 → 子组件 (单向) |
@Link | @Link value: number | 父组件 ↔ 子组件 (双向,使用 $varName) |
@Provide/@Consume | 跨层级 | 祖先组件 → 后代组件 |
@Observed/@ObjectLink | 嵌套对象 | 深层对象观察 |
| 装饰器 | 用法 | 描述 |
|---|---|---|
@ComponentV2 | @ComponentV2 struct MyComp | 启用 V2 状态管理 |
@Local | @Local count: number = 0 | 内部状态 (无外部初始化) |
@Param | @Param title: string = "" | 父组件 → 子组件 (单向,高效) |
@Event | @Event onChange: () => void | 子组件 → 父组件 (回调) |
@ObservedV2 | @ObservedV2 class Data | 类观察 |
@Trace | @Trace name: string | 属性级跟踪 |
@Computed | @Computed get value() | 缓存的计算属性 |
@Monitor | @Monitor('prop') onFn() | 监视变更 (包含变更前后) |
@Provider/@Consumer | 跨层级 | 跨组件树双向同步 |
完整 V2 指南请参阅references/state-management-v2.md。
// 垂直布局
Column({ space: 10 }) { Text('A'); Text('B'); }
.alignItems(HorizontalAlign.Center)
// 水平布局
Row({ space: 10 }) { Text('A'); Text('B'); }
.justifyContent(FlexAlign.SpaceBetween)
// 堆叠布局 (叠加)
Stack({ alignContent: Alignment.Center }) {
Image($r('app.media.bg'))
Text('Overlay')
}
// 使用 ForEach 的列表
List({ space: 10 }) {
ForEach(this.items, (item: string) => {
ListItem() { Text(item) }
}, (item: string) => item)
}
@Entry
@Component
struct Page {
aboutToAppear() { /* 初始化数据 */ }
onPageShow() { /* 页面可见时 */ }
onPageHide() { /* 页面隐藏时 */ }
aboutToDisappear() { /* 清理工作 */ }
build() { Column() { Text('Page') } }
}
import { router } from '@kit.ArkUI';
// 跳转
router.pushUrl({ url: 'pages/Detail', params: { id: 123 } });
// 替换
router.replaceUrl({ url: 'pages/New' });
// 返回
router.back();
// 获取参数
interface RouteParams {
id: number;
title?: string;
}
const params = router.getParams() as RouteParams;
import { http } from '@kit.NetworkKit';
const req = http.createHttp();
const res = await req.request('https://api.example.com/data', {
method: http.RequestMethod.GET,
header: { 'Content-Type': 'application/json' }
});
if (res.responseCode === 200) {
const data = JSON.parse(res.result as string);
}
req.destroy();
import { preferences } from '@kit.ArkData';
const prefs = await preferences.getPreferences(this.context, 'store');
await prefs.put('key', 'value');
await prefs.flush();
const val = await prefs.get('key', 'default');
ArkTS 为了性能和安全性,执行比 TypeScript 更严格的规则:
| 禁止项 | 替代方案 |
|---|---|
any, unknown | 显式类型,接口 |
var | let, const |
动态属性访问 obj['key'] | 固定的对象结构 |
for...in, delete, with | for...of, 数组方法 |
#privateField | private 关键字 |
| 结构类型 | 显式 implements/extends |
完整的 TypeScript → ArkTS 迁移细节请参阅 references/migration-guide.md。
hvigorw 是用于命令行构建的 Hvigor 包装工具。
# 常用构建任务
hvigorw clean # 清理构建目录
hvigorw assembleHap -p buildMode=debug # 构建 Hap (调试模式)
hvigorw assembleApp -p buildMode=release # 构建 App (发布模式)
hvigorw assembleHar # 构建 Har 库
hvigorw assembleHsp # 构建 Hsp
# 构建特定模块
hvigorw assembleHap -p module=entry@default --mode module
# 运行测试
hvigorw onDeviceTest -p module=entry -p coverage=true
hvigorw test -p module=entry # 本地测试
# CI/CD 推荐
hvigorw assembleApp -p buildMode=release --no-daemon
常用参数:
| 参数 | 描述 |
|---|---|
| `-p buildMode={debug | release}` |
-p product={name} | 目标产品 (默认: default) |
-p module={name}@{target} | 目标模块 (与 --mode module 一起使用) |
--no-daemon | 禁用守护进程 (推荐用于 CI) |
--analyze=advanced | 启用构建分析 |
--optimization-strategy=memory | 内存优化构建 |
完整命令参考请参阅 references/hvigor-commandline.md。
codelinter 是用于 ArkTS/TS 文件的代码检查和修复工具。
# 基本用法
codelinter # 检查当前项目
codelinter /path/to/project # 检查指定项目
codelinter -c ./code-linter.json5 # 使用自定义规则
# 检查并自动修复
codelinter --fix
codelinter -c ./code-linter.json5 --fix
# 输出格式
codelinter -f json -o ./report.json # JSON 报告
codelinter -f html -o ./report.html # HTML 报告
# 增量检查 (仅 Git 变更)
codelinter -i
# CI/CD 使用退出码
codelinter --exit-on error,warn # 遇到错误/警告时非零退出
| 参数 | 描述 |
|---|---|
-c, --config <file> | 指定规则配置文件 |
--fix | 自动修复支持的问题 |
-f, --format | 输出格式: default/json/xml/html |
-o, --output <file> | 保存结果到文件 |
-i, --incremental | 仅检查 Git 变更的文件 |
-p, --product <name> | 指定产品 |
-e, --exit-on <levels> | 退出码级别: error,warn,suggestion |
完整参考请参阅 references/codelinter.md。
hstack 将 Release 构建中的混淆崩溃堆栈解析回源代码位置。
# 解析崩溃文件目录
hstack -i crashDir -o outputDir -s sourcemapDir -n nameCacheDir
# 使用 C++ 符号解析
hstack -i crashDir -o outputDir -s sourcemapDir --so soDir -n nameCacheDir
# 解析单个崩溃堆栈
hstack -c "at func (entry|entry|1.0.0|src/main/ets/pages/Index.ts:58:58)" -s sourcemapDir
| 参数 | 描述 |
|---|---|
-i, --input | 崩溃文件目录 |
-c, --crash | 单个崩溃堆栈字符串 |
-o, --output | 输出目录 (或使用 -c 时的文件) |
-s, --sourcemapDir | Sourcemap 文件目录 |
--so, --soDir | 共享对象 (.so) 文件目录 |
-n, --nameObfuscation | NameCache 文件目录 |
要求:
-i 或 -c 之一 (不能同时提供)-s 或 --so-s 和 -n完整参考请参阅 references/hstack.md。
在 build-profile.json5 中启用:
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": ["./obfuscation-rules.txt"]
}
}
}
obfuscation-rules.txt 中的常用规则:
-enable-property-obfuscation # 属性名混淆
-enable-toplevel-obfuscation # 顶层作用域混淆
-enable-filename-obfuscation # 文件名混淆
-keep-property-name apiKey # 白名单特定名称
完整指南请参阅 references/arkguard-obfuscation.md。
harmonyos-build-deploy 技能每周安装数
52
仓库
GitHub 星标
5
首次出现
2026年2月4日
安全审计
安装于
opencode46
codex45
gemini-cli43
github-copilot43
cursor41
kimi-cli40
Build HarmonyOS applications using ArkTS and the ArkUI declarative UI framework.
Create a basic component:
@Entry
@Component
struct HelloWorld {
@State message: string = 'Hello, ArkTS!';
build() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
Button('Click Me')
.onClick(() => { this.message = 'Button Clicked!'; })
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
| Decorator | Usage | Description |
|---|---|---|
@State | @State count: number = 0 | Component internal state |
@Prop | @Prop title: string | Parent → Child (one-way) |
@Link | @Link value: number | Parent ↔ Child (two-way, use $varName) |
@Provide/@Consume | Cross-level | Ancestor → Descendant |
@Observed/@ObjectLink | Nested objects | Deep object observation |
| Decorator | Usage | Description |
|---|---|---|
@ComponentV2 | @ComponentV2 struct MyComp | Enable V2 state management |
@Local | @Local count: number = 0 | Internal state (no external init) |
@Param | @Param title: string = "" | Parent → Child (one-way, efficient) |
@Event |
Seereferences/state-management-v2.md for complete V2 guide.
// Vertical
Column({ space: 10 }) { Text('A'); Text('B'); }
.alignItems(HorizontalAlign.Center)
// Horizontal
Row({ space: 10 }) { Text('A'); Text('B'); }
.justifyContent(FlexAlign.SpaceBetween)
// Stack (overlay)
Stack({ alignContent: Alignment.Center }) {
Image($r('app.media.bg'))
Text('Overlay')
}
// List with ForEach
List({ space: 10 }) {
ForEach(this.items, (item: string) => {
ListItem() { Text(item) }
}, (item: string) => item)
}
@Entry
@Component
struct Page {
aboutToAppear() { /* Init data */ }
onPageShow() { /* Page visible */ }
onPageHide() { /* Page hidden */ }
aboutToDisappear() { /* Cleanup */ }
build() { Column() { Text('Page') } }
}
import { router } from '@kit.ArkUI';
// Push
router.pushUrl({ url: 'pages/Detail', params: { id: 123 } });
// Replace
router.replaceUrl({ url: 'pages/New' });
// Back
router.back();
// Get params
interface RouteParams {
id: number;
title?: string;
}
const params = router.getParams() as RouteParams;
import { http } from '@kit.NetworkKit';
const req = http.createHttp();
const res = await req.request('https://api.example.com/data', {
method: http.RequestMethod.GET,
header: { 'Content-Type': 'application/json' }
});
if (res.responseCode === 200) {
const data = JSON.parse(res.result as string);
}
req.destroy();
import { preferences } from '@kit.ArkData';
const prefs = await preferences.getPreferences(this.context, 'store');
await prefs.put('key', 'value');
await prefs.flush();
const val = await prefs.get('key', 'default');
ArkTS enforces stricter rules than TypeScript for performance and safety:
| Prohibited | Use Instead |
|---|---|
any, unknown | Explicit types, interfaces |
var | let, const |
Dynamic property access obj['key'] | Fixed object structure |
for...in, delete, |
See references/migration-guide.md for complete TypeScript → ArkTS migration details.
hvigorw is the Hvigor wrapper tool for command-line builds.
# Common build tasks
hvigorw clean # Clean build directory
hvigorw assembleHap -p buildMode=debug # Build Hap (debug)
hvigorw assembleApp -p buildMode=release # Build App (release)
hvigorw assembleHar # Build Har library
hvigorw assembleHsp # Build Hsp
# Build specific module
hvigorw assembleHap -p module=entry@default --mode module
# Run tests
hvigorw onDeviceTest -p module=entry -p coverage=true
hvigorw test -p module=entry # Local test
# CI/CD recommended
hvigorw assembleApp -p buildMode=release --no-daemon
Common parameters:
| Parameter | Description |
|---|---|
| `-p buildMode={debug | release}` |
-p product={name} | Target product (default: default) |
-p module={name}@{target} | Target module (with --mode module) |
--no-daemon | Disable daemon (recommended for CI) |
--analyze=advanced | Enable build analysis |
--optimization-strategy=memory |
See references/hvigor-commandline.md for complete command reference.
codelinter is the code checking and fixing tool for ArkTS/TS files.
# Basic usage
codelinter # Check current project
codelinter /path/to/project # Check specified project
codelinter -c ./code-linter.json5 # Use custom rules
# Check and auto-fix
codelinter --fix
codelinter -c ./code-linter.json5 --fix
# Output formats
codelinter -f json -o ./report.json # JSON report
codelinter -f html -o ./report.html # HTML report
# Incremental check (Git changes only)
codelinter -i
# CI/CD with exit codes
codelinter --exit-on error,warn # Non-zero exit on error/warn
| Parameter | Description |
|---|---|
-c, --config <file> | Specify rules config file |
--fix | Auto-fix supported issues |
-f, --format | Output format: default/json/xml/html |
-o, --output <file> | Save result to file |
-i, --incremental | Check only Git changed files |
-p, --product <name> | Specify product |
See references/codelinter.md for complete reference.
hstack parses obfuscated crash stacks from Release builds back to source code locations.
# Parse crash files directory
hstack -i crashDir -o outputDir -s sourcemapDir -n nameCacheDir
# Parse with C++ symbols
hstack -i crashDir -o outputDir -s sourcemapDir --so soDir -n nameCacheDir
# Parse single crash stack
hstack -c "at func (entry|entry|1.0.0|src/main/ets/pages/Index.ts:58:58)" -s sourcemapDir
| Parameter | Description |
|---|---|
-i, --input | Crash files directory |
-c, --crash | Single crash stack string |
-o, --output | Output directory (or file with -c) |
-s, --sourcemapDir | Sourcemap files directory |
--so, --soDir | Shared object (.so) files directory |
-n, --nameObfuscation |
Requirements:
-i or -c (not both)-s or --so-s and -nSee references/hstack.md for complete reference.
Enable in build-profile.json5:
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": ["./obfuscation-rules.txt"]
}
}
}
Common rules in obfuscation-rules.txt:
-enable-property-obfuscation # Property name obfuscation
-enable-toplevel-obfuscation # Top-level scope obfuscation
-enable-filename-obfuscation # Filename obfuscation
-keep-property-name apiKey # Whitelist specific names
See references/arkguard-obfuscation.md for complete guide.
harmonyos-build-deploy skill for building, packaging, and device installationWeekly Installs
52
Repository
GitHub Stars
5
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode46
codex45
gemini-cli43
github-copilot43
cursor41
kimi-cli40
Angular开发者指南:从项目创建到组件与信号式状态管理的最佳实践
638 周安装
@Event onChange: () => void |
| Child → Parent (callback) |
@ObservedV2 | @ObservedV2 class Data | Class observation |
@Trace | @Trace name: string | Property-level tracking |
@Computed | @Computed get value() | Cached computed properties |
@Monitor | @Monitor('prop') onFn() | Watch changes with before/after |
@Provider/@Consumer | Cross-level | Two-way sync across tree |
withfor...of, array methods |
#privateField | private keyword |
| Structural typing | Explicit implements/extends |
| Memory-optimized build |
-e, --exit-on <levels> | Exit code levels: error,warn,suggestion |
| NameCache files directory |