@oh-expo/expo-asset
v55.0.20-harmony.0
Published
expo-asset 的 HarmonyOS 适配包(ExpoModule 原生模块,expo-modules-core 体系)
Maintainers
Readme
@oh-expo/expo-asset
让
expo-asset(资源下载/缓存)在 HarmonyOS / OpenHarmony 上运行的适配包。
通过 expo-modules-core 体系提供 ExpoAssetModule 原生模块(模块名 ExpoAsset),
接口收口自 [email protected] 权威 d.ts。
支持基线
| 项 | 值 |
| --- | --- |
| 适配目标 | [email protected] |
| 运行时底座 | @expo-harmony/[email protected](本地 HAR) |
| 鸿蒙 SDK | API 26(SDK 26.0.0 锚定,@ohos.file.fs/fileuri/hash + @ohos.request + cryptoFramework) |
| 权限 | 无(网络下载走系统下载服务) |
实现面
downloadAsync(uri, md5, type)→ localUri(file: uri):rawfile 资源复制(getRawFd 流式读取)、 HTTP(S) 下载(downloadFile + complete/fail 事件)、缓存命中校验(fs.access + MD5 匹配)、fileUriFromPath归一化;- 在途请求收敛:同 key 去重(inflight map)、onPrepareForReload/onDestroy 取消并等待;
- 诚实分级:file: uri 直通返回;非 http/https/rawfile 的 scheme 报 ERR_ASSET_UNSUPPORTED_URI。
快速开始
安装 npm 包(peer 依赖
expo-asset原包与 expo-modules-core 自动安装):npm install @oh-expo/expo-asset拷贝 HAR 到宿主并声明 ohpm 依赖:
cp node_modules/@oh-expo/expo-asset/local-hars/expo_asset.har harmony/local-hars/// harmony/oh-package.json5 { "dependencies": { "@oh-expo/expo-asset": "file:local-hars/expo_asset.har" } }JS 侧使用(对外契约由原包提供):
import { Asset } from 'expo-asset';
构建与校验
pnpm har:prepare # hvigorw assembleHar → local-hars/expo_asset.har
pnpm har:prepack # 发布前校验(必需文件 / scope / -harmony.N 版本 / HAR 产物)状态与来源
- ⚠️ 实现已落盘并经 assembleHar / 宿主接入编译验证(真机功能验证 ⏳);
- 接口契约锚定
[email protected]权威 d.ts,规格见主仓docs/adaptations/expo-asset.md与acceptance/ledger.md(S4 前置门口径)。
