configureLaunchScreen
从一张源图生成 Android 各密度启动屏 drawable 资源。
前置依赖
| 参数名 | 类型 | 说明 |
|---|---|---|
deps.existsSync / readFileSync / writeFileSync | 文件读写 | 源图与输出 |
deps.mkdirSync / join / dirname | 目录与路径 | 创建 drawable 目录 |
deps.sharp | Sharp | 按密度缩放 |
环境要求
- Node.js + sharp
函数签名
typescript
function configureLaunchScreenAndroid(
imagePath: string,
projectPath: string,
moduleDir: string,
deps: ConfigureLaunchScreenAndroidDeps,
): Promise<ConfigureLaunchScreenAndroidResult>参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
imagePath | string | 是 | 启动图源文件 |
projectPath | string | 是 | Android 工程根 |
moduleDir | string | 是 | 如 app |
deps | ConfigureLaunchScreenAndroidDeps | 是 | 环境依赖 |
返回值
| 类型 | 说明 |
|---|---|
ConfigureLaunchScreenAndroidResult | { success, error?, logs[] } |
工作原理
- 按
ANDROID_LAUNCH_SCREEN_SIZES为 ldpi~xxxhdpi 生成对应宽高图片。 - 写入
res/drawable-{density}/并配置启动屏相关资源(见源码 manifest/styles 步骤)。 - 全程收集 logs,失败返回 error 文案。